Page type controller

Permalink 1 user found helpful
Hello all,

I have crested a package that has a page type and a page type controller. I need a way to access that page type's controller from a different file. The following is not working.

$theController = Loader::controller('THE_PAGE_TYPE_HANDLE');
$result = $theController->THE_FUNCTION();

I would really appreciate any help I can get. HELP!!!

-Rachel

rsmitty
 
mkly replied on at Permalink Best Answer Reply
mkly
I don't know if this is the prettiest but...

require_once Loader::pageTypeControllerPath('my_page_type_handle');
$page_type_controller = new MyPageTypePageTypeController();
$page_type_controller->some_method();


replace the handle and the controller name and method with your stuff.
rsmitty replied on at Permalink Reply
rsmitty
YOU ROCK!!! That worked perfectly!!!
aghouseh replied on at Permalink Reply
aghouseh
This is EXACTLY what I was trying to do.

Now here's a follow-up.. what would be the recommended method of ensuring that on all single_pages throughout the site run a certain method from my pagetype controller?
jordanlev replied on at Permalink Reply
jordanlev
single_pages don't have anything to do with page_type controllers. So I think your best bet is to just have something run on the on_start event (or some other event that happens early on in the C5 loading process), check if the requested page is a single_page (but probably wanting to exclude dashboard pages?), then run your method from there.
navteca replied on at Permalink Reply
I am facing a similar problem. I have a package that contains a theme and in that theme i have created a custom page_type, pdftor

pdftor has a "hard coded" form, hard coded in the sense that it isn't part of a block.

I have created a folder like /packages/pdfcreator/theme/pdfcreator/pdftor.php
for the custom page
and
/packages/controllers/page_types/pdftor.php for the custom page controller

But it is not loading the controller, i have tested putting an echo on the on_page_view() function but it does not run it.

Any suggestions

?

Ramon
rsmitty replied on at Permalink Reply
rsmitty
I'm not entirely sure, but I don't think you can have a theme folder in a package folder. You can just put a page_types folder in the package folder though.
jordanlev replied on at Permalink Reply
jordanlev
You can have themes and page_types in your package (one, both, neither, whatever). But your package controller needs to install them. And you need to get the naming of things correct.

The theme needs to be in a folder called "themes" (note that it is plural, ending with the letter "s" -- not singular "theme" like you say you have), and inside that "themes" folder needs to be your theme's folder with the theme handle as the folder name. For example, if your theme has the handle "pdfcreator", then all your theme files would be in here:
/packages/pdfcreator/themes/pdfcreator/

Most marketplace themes have the package name prefixed with "theme_", which might be necessary, so try renaming your package to "theme_pdfcreator" (and the package handle in the package controller, and the package controller class name).

And make sure your install function of your package controller is actually installing the theme (or page_type, or whatever).

Good luck!