One Controller for multiple Single Pages
Permalink 4 users found helpful
Hi
Is it possible to use a single controller for multiple single pages? If possible then whats is the process?
Additionally how can I call a single page into the view method of controller? I'm aware about the controller naming convention. But still get "Page not found".
Citytech
Is it possible to use a single controller for multiple single pages? If possible then whats is the process?
Additionally how can I call a single page into the view method of controller? I'm aware about the controller naming convention. But still get "Page not found".
Citytech
For those concerned... the above works in 5.4.2.2 as well. :)
Beyond that, concrete5's Single Page Controllers aren't full fledged controllers so it's tough to do things like that and you sometimes run into odd problems.
You are probably better off just keeping to one controller per view, which violates basic MVC principals, but it's kind of just the way it is.
You are probably better off just keeping to one controller per view, which violates basic MVC principals, but it's kind of just the way it is.
You could turn the problem inside out.
Put most of your controller logic into a library, then inherit that library into each of your (now minimal) single page controllers and override/add as you need to.
Put most of your controller logic into a library, then inherit that library into each of your (now minimal) single page controllers and override/add as you need to.
+1 Excelent idea! Thanks!
How to get that:
You move the controller file to a library (/libraries/controllers/single_page_handle) and then in the old controller.php you remove all code and add this
How to get that:
You move the controller file to a library (/libraries/controllers/single_page_handle) and then in the old controller.php you remove all code and add this
Loader::library('controllers/single_page_handle/controller', 'package_handle');
Hi
I have a controller which name is event_type_details.php
Path of this controller is /controllers/dashboard/pkgname/event_type_details.php
I have a single page with the same name above & the path is /single_pages/dashboard/pkgname/event_type_details.php
When I try to open this page it shows "Page not found!". Am I doing something wrong?
Citytech
I have a controller which name is event_type_details.php
Path of this controller is /controllers/dashboard/pkgname/event_type_details.php
class DashboardC5EventEventTypeDetailsController extends Controller { /* code goes here */ }
I have a single page with the same name above & the path is /single_pages/dashboard/pkgname/event_type_details.php
When I try to open this page it shows "Page not found!". Am I doing something wrong?
Citytech
If the package is called c5_event then the path looks OK.
You also need to register the single page with C5 when the package is installed.
Have a look at the package controller and single page & controller paths for a marketplace package. phpinfo comes to mind as I was only working on it a couple of weeks ago and it has one single page.
You also need to register the single page with C5 when the package is installed.
Have a look at the package controller and single page & controller paths for a marketplace package. phpinfo comes to mind as I was only working on it a couple of weeks ago and it has one single page.
Hi John,
If the package is called c5_event then the path looks OK.
Ans: The package is called c5event. No underscore between c5 & event.
You also need to register the single page with C5 when the package is installed.
Ans: How could I do this?
If the package is called c5_event then the path looks OK.
Ans: The package is called c5event. No underscore between c5 & event.
You also need to register the single page with C5 when the package is installed.
Ans: How could I do this?
No one is there to help me out. I'm in a trouble.
Citytech
Citytech
Oh, just clear you cache.
Its not the cache problem. I've cleared it several times.
Ok, I see. It's the camel casing algorithm.
Try
See
https://github.com/concrete5/concrete5/blob/master/web/concrete/libr...
Try
class DashboardC5eventEventTypeDetailsController extends Controller {
See
https://github.com/concrete5/concrete5/blob/master/web/concrete/libr...
Hi mkly,
Thanks for your help so far. I've just solved the issue by using $this->render('path/file'); in the same controller. Previously I was creating 2 controllers for add/edit page & listings page. But now I'm just using only one controller & define a function to execute the other. Thanks once again.
Citytech
Thanks for your help so far. I've just solved the issue by using $this->render('path/file'); in the same controller. Previously I was creating 2 controllers for add/edit page & listings page. But now I'm just using only one controller & define a function to execute the other. Thanks once again.
Citytech
Hi Citytech,
I'm glad you got this working. Having multiple views ("single_pages") for one controller file is something I do a lot (I'm the person that contributed the patch that @mkly links to above). You might be interested in this boilerplate code I have available, which makes heavy use of this pattern, and also documents a lot of best practices and C5 "gotchas" in the code comments:
https://github.com/jordanlev/c5_boilerplate_crud...
-Jordan
I'm glad you got this working. Having multiple views ("single_pages") for one controller file is something I do a lot (I'm the person that contributed the patch that @mkly links to above). You might be interested in this boilerplate code I have available, which makes heavy use of this pattern, and also documents a lot of best practices and C5 "gotchas" in the code comments:
https://github.com/jordanlev/c5_boilerplate_crud...
-Jordan
Thanks Jordon for helping.
Citytech
Citytech
Nice patch Jordan! This is really helpful, because I found it very ugly to do it all on one view-page. :)
EXACTLY what i was looking for. Thank you Jordanlev!
To a particular view file as of 5.5 due to this commit
https://github.com/concrete5/concrete5/commit/c5c08e351e14eb5d6d03ba...