Can't access to the controller from a single page view

Permalink
I try since hours to access to the methods of my controller from the view of a single page.
I've got a package build like that :

packages/bp/single_pages/dashboard/portal/view.php
packages/bp/controllers/dashboard/portal/controller.php

My controller is declare as:
DashboardPortalController extends Controller

And in my view I do $this->controller and I can't access to my vars or methods...

I don't understand what I do wrong.

PS: sorry for my english, I'm french... ;)

 
jordanlev replied on at Permalink Reply
jordanlev
I think it's just $controller (no "$this"). So if you have a public function called "foo", you can call it from the single_page like so:
$controller->foo();
JohntheFish replied on at Permalink Reply
JohntheFish
I have been using:

$cinfo = $this->controller->controller_method();


On a single page I am developing and it seems to be working OK.
mehdimoi replied on at Permalink Reply
Thank you for your answers.

When i do a var_dump($this) I can see the controller and I can access by the $this->controller. But this controller don't have my methods. It seems to be a generic controller but not the one that I wrote.

So I think something is wrong in the structure of my files or in the function install of my package.

Loader::model('single_page');
$page=SinglePage::add('portal',$pkg);


Do I have to mention something more to intall the controller?
Or is it the core that scan my folder 'controllers' in my package?
JohntheFish replied on at Permalink Reply
JohntheFish
I have only been developing a single page that presents end user content, not within the dashboard. However, my guess is that your single page controller is not installed. In the package controller (packages/bp/controller.php) you need something like:
public function install() {
    $pkg = parent::install();
    Loader::model('single_page');
    $def = SinglePage::add('/dashboard/portal', $pkg);
    // and other stuff you want to install with the package
}


You need to uninstal then reinstall your bp package for this to run.
mehdimoi replied on at Permalink Reply
That's exactly what I did (sorry there's a mistake in my previous post)

And i even add a delete if a single page with the same path is found...
I really don't understand because I do exactly the same that you and that what is write in the doc

public function install() {
      $pkg = parent::install();
       Loader::model('single_page');
      $existpage = Page::getByPath('/dashboard/portal');
   if(is_object($existpage )){
      $existpage ->delete();
         }
    $page2=SinglePage::add('/dashboard/portal',$pkg);
       $page2->update(array('cName'=>t('Portail'),'cDescription'=>t('Connection au Portail.')));
   }
jordanlev replied on at Permalink Reply
jordanlev
Please post the full path to both your controller and your single page (starting from the top level of your site) -- there may be a naming mismatch which prevents C5 from finding the right controller file.
JohntheFish replied on at Permalink Reply
JohntheFish
I went through this a few weeks ago with similar frustration and am now trying to think back to what the various stages of failure were before I got it to work.

A few more ideas (I suspect you will have already tried much of this):
- Hack in (temporarily) a Log::addEntry('My single page is installing here') to the install to confirm it is running correctly.
- Double check the NameCase vs name_case of the package and page controllers and files etc all match up correctly and that the correct controllers are being extended (Edit: I see Jordanlev has already mentioned this).
- Deliberately put some erroneous code in your single page controller, so you can confirm it is being used because you will get a php error.
mehdimoi replied on at Permalink Reply
I just try to put bad content in the controller, there is no php error...

This is the structure of my package :
concrete
    |_ packages
         |_bp
            |_controllers
                  |_dashboard
                          |_portal
                               |_controller.php
            |_single_pages
                  |_dashboard
                          |_portal
                               |_view.php

My controller is 'DashboardPortalController'

Is the structure right?
12345j replied on at Permalink Reply
12345j
should be in root/packages, not concrete/packages You don't need the _ at the beggining of each file or folder.
mehdimoi replied on at Permalink Reply
Sorry, concrete represents the root in my schema, not the concrete folder...
And the underscore are also just a part of my strange schema lol