Trouble loading a Single Page Controller
Permalink
I thought I would post a crude & temporary fix I did here in the hope that I can gain insight into a better way to apply it.
I have a single page, whose file I named 'account-pin.php' in my \application\single_pages folder and I successfully added this as a single page through the dashboard to reach it over the desired path /account-pin.
Now I want to add a single page controller for this page so that I can prepare some data in the 'view' function. Therefore, I instinctively created an account-pin.php file due to my pre 5.7 knowledge.
The contents of this controller file were not being loaded and I don't mean that the class was not being loaded - the autoloading was not loading the file at all.
In another project, it appeared the '-' was the problem and I renamed my single pages so they didn't use a '-'. This was ok in that project but not in my current one and is a less than ideal hack anyhow.
So I looked under the covers more and realised that to load the single page controller files, I had to rename that file to AccountPin.php according to the convention and add the following line to /concrete/src/Foundation/ClassLoader.php (around line 222):
Yes, I know I shouldn't change this file direct but I also don't feel comfortable in overriding it properly just for this.
Therefore, any tips on how I should manage this properly in 5.7?
Thanks in advance.
I have a single page, whose file I named 'account-pin.php' in my \application\single_pages folder and I successfully added this as a single page through the dashboard to reach it over the desired path /account-pin.
Now I want to add a single page controller for this page so that I can prepare some data in the 'view' function. Therefore, I instinctively created an account-pin.php file due to my pre 5.7 knowledge.
The contents of this controller file were not being loaded and I don't mean that the class was not being loaded - the autoloading was not loading the file at all.
In another project, it appeared the '-' was the problem and I renamed my single pages so they didn't use a '-'. This was ok in that project but not in my current one and is a less than ideal hack anyhow.
So I looked under the covers more and realised that to load the single page controller files, I had to rename that file to AccountPin.php according to the convention and add the following line to /concrete/src/Foundation/ClassLoader.php (around line 222):
$symfonyLoader->addPrefix($namespace . '\\Controller\\SinglePage', DIR_APPLICATION . '/' . DIRNAME_CONTROLLERS . '/' . DIRNAME_PAGE_CONTROLLERS);
Yes, I know I shouldn't change this file direct but I also don't feel comfortable in overriding it properly just for this.
Therefore, any tips on how I should manage this properly in 5.7?
Thanks in advance.
Thanks for the reply Hutman and thanks for raising the bug.
I wasn't aware of the alternate work around by including in a package so thanks for that too.
Let's see what comes back from that bug report.
Regards,
Dan
I wasn't aware of the alternate work around by including in a package so thanks for that too.
Let's see what comes back from that bug report.
Regards,
Dan
This is really weird but I've rolled out the site I've built to a different environment (also running Ubuntu like in my dev environment) and here adding the file as account-pin.php works and my hackfix doesn't.
Now I'm really lost as to why.
Now I'm really lost as to why.
When you say "adding the file as account-pin.php works" do you mean the single page or the controller for the single page?
To answer your question: In the controllers/single_page folder.
It gets weirder - I actually need both a file named account-pin.php and AccountPin.php for it to work.
As my dev environment is a VM, the VM web server had this without me knowing as renaming in my IDE simply left the old file and created a new one.
In the new environment this happened to only get resolved when adding the account-pin.php file.
It gets weirder - I actually need both a file named account-pin.php and AccountPin.php for it to work.
As my dev environment is a VM, the VM web server had this without me knowing as renaming in my IDE simply left the old file and created a new one.
In the new environment this happened to only get resolved when adding the account-pin.php file.
This might not be very helpful, but I do know that you can do this using a package and it works properly. If you would like an example of how to create a package that just installs a single page please let me know and I'll be happy to send you one.
The package structure would look like this:
/package_name/controller.php
/package_name/single_pages/account-pin.php
/package_name/controllers/single_page/account_pin.php