Page Type Controllers for Packages Not Loading
Permalink
I've created a package for a custom theme and I obviously have my own page types. I'm trying to create my own page type controller within the package but it's not getting loaded. I'm seeing some others having issues with this but nothing resolved. Wondering if anyone had a fix or not. I'm able to do so outside of the package but I'd like the controller IN my package. Here's my code:
<?php namespace Concrete\Package\MyPackageName\Controller\PageType; use Concrete\Core\Page\Controller\PageTypeController; class Home extends PageTypeController { public function view() { $this->set('debug','test'); } }
The page type and controller was NOT there when I started developing the package...perhaps this has something to do with it? Not sure how to go about adding the page type controller after the fact...maybe in the upgrade function of the packages controller? The page type has already been added (and used) through the site, however...not sure if that makes a difference..
Is the Page Type connected to the package? If it is not the system will never look for the controller in your package, it will only look in /application and /concrete.
It is not. Not sure how I would go about doing that. Would I just add the
page type in the package controller install method? I've already manually
added the page type so not sure how I would go about doing that...
page type in the package controller install method? I've already manually
added the page type so not sure how I would go about doing that...
Here is some code I used for 5.6 to achieve this, it should be really similar if you are using 5.7, otherwise you can log in to your database, check the Packages table, get the ID of your package and update the Page Types table with that ID in the pkgID field.
$ct_handle = CollectionType::getByHandle('page_type_handle'); if (!is_object($ct_handle)) { $data = array('ctHandle' => 'home', 'ctName' => t('Home')); $ct_handle = CollectionType::add($data, $pkg); } else { Loader::db()->execute('UPDATE PageTypes SET pkgID = ? WHERE ctHandle = ?', array($pkg->pkgID, 'page_type_handle')); }
Also, was the Controller there when you created the page type? Sometimes adding a controller after the fact within a package can make things complicated.