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

citytech2
View Replies: View Best Answer
mkly replied on at Permalink Best Answer Reply
mkly
I'm pretty sure that you can do
$this->render('path/file');

To a particular view file as of 5.5 due to this commit
https://github.com/concrete5/concrete5/commit/c5c08e351e14eb5d6d03ba...
olsgreen replied on at Permalink Reply
olsgreen
For those concerned... the above works in 5.4.2.2 as well. :)
mkly replied on at Permalink Reply
mkly
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.
JohntheFish replied on at Permalink Reply
JohntheFish
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.
Arequal replied on at Permalink Reply
Arequal
+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

Loader::library('controllers/single_page_handle/controller', 'package_handle');
citytech2 replied on at Permalink Reply
citytech2
Hi
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
JohntheFish replied on at Permalink Reply
JohntheFish
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.
citytech2 replied on at Permalink Reply
citytech2
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?
citytech2 replied on at Permalink Reply
citytech2
No one is there to help me out. I'm in a trouble.

Citytech
mkly replied on at Permalink Reply
mkly
Oh, just clear you cache.
citytech2 replied on at Permalink Reply
citytech2
Its not the cache problem. I've cleared it several times.
mkly replied on at Permalink Reply
mkly
Ok, I see. It's the camel casing algorithm.

Try
class DashboardC5eventEventTypeDetailsController extends Controller {


See
https://github.com/concrete5/concrete5/blob/master/web/concrete/libr...
citytech2 replied on at Permalink Reply
citytech2
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
jordanlev replied on at Permalink Reply
jordanlev
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
citytech2 replied on at Permalink Reply
citytech2
Thanks Jordon for helping.

Citytech
programmieraffe replied on at Permalink Reply
programmieraffe
Nice patch Jordan! This is really helpful, because I found it very ugly to do it all on one view-page. :)
ssdscott replied on at Permalink Reply
ssdscott
EXACTLY what i was looking for. Thank you Jordanlev!