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');
    }
}

stephendmalloy
 
hutman replied on at Permalink Reply
hutman
Was your Page Type installed with the Package? With 5.6 you had to have the Page Type connected to the package in order for the page type controller to look in the package folder, I would imaging it's the same for 5.7.

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.
stephendmalloy replied on at Permalink Reply
stephendmalloy
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..
hutman replied on at Permalink Reply
hutman
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.
stephendmalloy replied on at Permalink Reply
stephendmalloy
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...
hutman replied on at Permalink Reply
hutman
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'));
}