I am starting to work on turning my CMS blog into components.
What is the best way to handle custom components in a php pages that include separate php code stored in a folder.
For example in my forthcoming CMS blog, there will be a number of components that typically be added to their own page e.g. list blog posts, view blog posts, edit blog posts etc.
Currently my PHP code includes routines store in a common ‘handlers’ folder at the root level; routines such as retrieve metadata, autosave, upload image, delete post, save post etc. The PHP code in the components will include these routines e.g. ‘require_once “handlers/metadata.php”;’
It is also likely that I would like to have a common component that would likely be in a global, that would be setup to initialise the CMS blog environment?
Hi @tpbradley,
I have tried this out and if you store it the component’s templates folder with the component, it is being stored in the backend folder.
However, AFAICS, if you try and install a PHP included file in the DevPack’s ‘shared/templates/backend’ it isn’t getting saved in the e.g. ‘backend/rw090101E2_026E_4DE0_A3F4_46606F517DF6’ folder.
A number of my included PHP files are used in multiple components.
To add to the above; if I add a folder to the ‘backend’ folder, with some PHP files in, when I publish the Elements project, there are no error messages produced (that I can detect) none of the pageStart DevPack PHP code is included in the published index.php file, although the HTML code is. The DevPack debug messages has nothing in it.
So it was only by interrogating the published index.php file that I could see that the PHP code wasn’t included.
Moving the sub-folders PHP files, up a level, into the backend folder and removing the sub-folder resolves the issue
It would be useful (though not a show stopper) to have sub-folders as it would help to keep things more organised.
I’ve been able to reproduce this here - add a subdirectory to the backend directory and everything within backend fails to publish. I’ve added a warning to the docs about this, along with a ticket to add support for subdirectories.
Actually, having chatted internally about it, I had forgotten we hit issues trying to do this before. However, we came up with a solution using a combination of files in backend and in shared/assets.
Essentially, you’d store your library code (stuff that doesn’t change) in the shared/assets directory. Then include it from your backend files, calling the functions with the component properties.
It’s a little tricky to see but I’m fairly certain the shared directory in the dev pack just needs to be moved into the components directory, so you should have