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:

<?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;
   }


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

alexaalto
View Replies: View Best Answer
alexaalto replied on at Permalink Reply
alexaalto
...so I'm trying to see if my controller is the controller being used to render this. I've put "var_dump($this);" in the php of the single page and get the following:

object(View)[3]
  private 'viewPath' => string '/dashboard/pages/page_categories' (length=32)
  public 'controller' => 
    object(Controller)[85]
      public 'theme' => null
      private 'sets' => 
        array
          empty
      protected 'helperObjects' => 
        array
          'html' => 
            object(HtmlHelper)[86]
              ...
      protected 'c' => 
        object(Page)[75]


The question is, should I see something identifying my controller (eg. btHandle) if it was being used?
alexaalto replied on at Permalink Reply
alexaalto
...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.
alexaalto replied on at Permalink Reply
alexaalto
...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:

$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!
alexaalto replied on at Permalink Best Answer Reply
alexaalto
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:

$class = Object::camelcase($path) . 'Controller';


Sadly I missed this in the book!

Alex
alexaalto replied on at Permalink Reply
alexaalto
...as clearly noted in the documentation here:

http://www.concrete5.org/documentation/developers/pages/mvc-approac...