Single Page Controllers

Permalink
I know this question has been asked before but struggling to get a single page controller to fire when visiting the single page in question. The single page is being installed as part of a package and the view.php file is displaying as expected but as above the controller doesnt do anything (even if I break the code).

My package structure looks like this
/packages/project_package/single_pages/my_page/view.php
/packages/project_package/controllers/single_pages/my_page/controller.php

The controller:
<?php
Concrete\Package\ProjectPackage\Controller\SinglePage\MyPage
use Concrete\Core\Page\Controller\PageController;
use Loader;
class Controller extends PageController {}


Any help with this much appreciated. I am assuming its a namespace issue as it usually is but cant get it to work

mikemiller
 
mesuva replied on at Permalink Best Answer Reply
mesuva
I'd write my controller this way:
<?php
namespace Concrete\Package\ProjectPackage\Controller\SinglePage;
use \Concrete\Core\Page\Controller\PageController;
class MyPage extends PageController {
    public function view() {
// stuff
    }
}
?>

I'd name this controller file
/packages/project_package/controllers/single_page/my_page.php

and I'd put the single page file:
/packages/project_package/single_pages/my_page.php
or
/packages/project_package/single_pages/my_page/view.php (either works)

If you update the location of these files you either have to reinstall your package or refresh the pages within the Single Pages section of the dashboard (otherwise c5 doesn't know where to look)
mikemiller replied on at Permalink Reply
mikemiller
Gotcha! Worked perfectly thanks very much
mesuva replied on at Permalink Reply
mesuva
Awesome, great to hear.

I've sort of found that once I've got the namespace 'pattern' worked out for blocks and page controllers, it's actually not that bad.

I actually am really liking the whole 'use Blah' way to pull in some class from somewhere else.

The other nice thing is that the concrete folder itself follows the same patterns for blocks and pages, so if I get mixed up a bit there are lots of examples right there in the code to refer to.
mikemiller replied on at Permalink Reply
mikemiller
Yeah I agree generally a fan but as you say need to get head round the namespace pattern (not that its hard but do end up going a bit blind after staring at a list of them for a while and then missing the obvious). The single pages turn out to be a bit of an anomaly (at least in my limited experience) as they dont demand to be called "controller.php" which is what had caught me out. Anyway all good now until the next head scratcher. Cheers again for the help!