Problem with Package Single Page Controller
Permalink
Hello again!
I'm trying to implement a package based upon the book "Concrete5 Beginner's Guide" and my singe page controller seems to be ignored. Specifically I have a "page_categories" package with the following single file layout:
page_categories -> controllers -> dashboard -> pages -> page_categories.php
page_categories -> single_pages -> dashboard -> pages -> page_categories.php
If I go to the "Pages" section of the dashboard, the single page appears, but I'm unable to see any data set in the controller and none of the Log::addEntry() calls are being executed in the controller making me think that it's not being run at all. Finally the helper I'm loading in the controller are not available in the single page. The controller looks like:
What could I be missing? I thought the controller was magically used if it had the same file name, non?
Thanks for any advice!
Alex
I'm trying to implement a package based upon the book "Concrete5 Beginner's Guide" and my singe page controller seems to be ignored. Specifically I have a "page_categories" package with the following single file layout:
page_categories -> controllers -> dashboard -> pages -> page_categories.php
page_categories -> single_pages -> dashboard -> pages -> page_categories.php
If I go to the "Pages" section of the dashboard, the single page appears, but I'm unable to see any data set in the controller and none of the Log::addEntry() calls are being executed in the controller making me think that it's not being run at all. Finally the helper I'm loading in the controller are not available in the single page. The controller looks like:
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); class DashboardPageCategoriesController extends Controller { public $helpers = array('form', 'html'); public function view() { Log::addEntry('Calling $this->getCategories();'); $categories = $this->getCategories(); $this->set('categories', $categories); } public function getCategories() { $db = Loader::db(); $categories = $db->GetAssoc('SELECT categoryID,category FROM btPageCategoriesCategories ORDER BY category'); Log::addEntry('getCategories called!'); return $categories; }
Viewing 15 lines of 16 lines. View entire code block.
What could I be missing? I thought the controller was magically used if it had the same file name, non?
Thanks for any advice!
Alex
...and can anyone verify that this directory structure is correct?
Alexs-MacBook-Pro:packages alex$ cd page_categories/
Alexs-MacBook-Pro:page_categories alex$ ls -l
total 8
drwxr-xr-x 3 alex alex 102 28 Sep 09:44 blocks
-rw-r--r-- 1 alex alex 698 28 Sep 13:38 controller.php
drwxr-xr-x 3 alex alex 102 28 Sep 09:51 controllers
drwxr-xr-x 2 alex alex 68 28 Sep 10:13 libraries
drwxr-xr-x 3 alex alex 102 28 Sep 09:51 single_pages
Alexs-MacBook-Pro:page_categories alex$ find controllers
controllers
controllers/dashboard
controllers/dashboard/page_categories.php
controllers/dashboard/pages
controllers/dashboard/pages/page_categories.php
Alexs-MacBook-Pro:page_categories alex$ find single_pages
single_pages
single_pages/dashboard
single_pages/dashboard/pages
single_pages/dashboard/pages/page_categories.php
Alexs-MacBook-Pro:page_categories alex$
I'm trying different locations for the controller to see if it helps.
Alexs-MacBook-Pro:packages alex$ cd page_categories/
Alexs-MacBook-Pro:page_categories alex$ ls -l
total 8
drwxr-xr-x 3 alex alex 102 28 Sep 09:44 blocks
-rw-r--r-- 1 alex alex 698 28 Sep 13:38 controller.php
drwxr-xr-x 3 alex alex 102 28 Sep 09:51 controllers
drwxr-xr-x 2 alex alex 68 28 Sep 10:13 libraries
drwxr-xr-x 3 alex alex 102 28 Sep 09:51 single_pages
Alexs-MacBook-Pro:page_categories alex$ find controllers
controllers
controllers/dashboard
controllers/dashboard/page_categories.php
controllers/dashboard/pages
controllers/dashboard/pages/page_categories.php
Alexs-MacBook-Pro:page_categories alex$ find single_pages
single_pages
single_pages/dashboard
single_pages/dashboard/pages
single_pages/dashboard/pages/page_categories.php
Alexs-MacBook-Pro:page_categories alex$
I'm trying different locations for the controller to see if it helps.
...interestingly if I break the controller code by adding a syntax error, it does indeed breaks everything. So I guess it is being run? But then why doesn't the code:
...does not show up in the view if I used:
I'm starting to pull hair out - someone please help me save my hair!
$this->set('myvalue',"HELLO WORLD");
...does not show up in the view if I used:
echo $myvalue;
I'm starting to pull hair out - someone please help me save my hair!
SOLUTION FOUND!
After tracing the code with Eclipse I see that line 470 in the loader.php is creating a name from the file PATH to be used as the class name. So in my case having the single page in "/dashboard/pages/page_categories" assumes the controller class name will be "DashboardPagesPageCategoriesController" by virtue if the line:
Sadly I missed this in the book!
Alex
After tracing the code with Eclipse I see that line 470 in the loader.php is creating a name from the file PATH to be used as the class name. So in my case having the single page in "/dashboard/pages/page_categories" assumes the controller class name will be "DashboardPagesPageCategoriesController" by virtue if the line:
$class = Object::camelcase($path) . 'Controller';
Sadly I missed this in the book!
Alex
...as clearly noted in the documentation here:
http://www.concrete5.org/documentation/developers/pages/mvc-approac...
http://www.concrete5.org/documentation/developers/pages/mvc-approac...
The question is, should I see something identifying my controller (eg. btHandle) if it was being used?