Controller + Single_page = No Go

Permalink
Hi folks,

I've just picked up Concrete5 as my CMS/Framework of choice but there are still some concepts I can't really grok.

I now that some other people have asked quite the same question before but the error message I get seems to be a different response than what they got.

So I have a view and its controller:

1. application/single_pages/products.php
2. application/controllers/single_page/products.php

Their respective code is:

<?php namespace Application\Controller\SinglePage;
use \Concrete\Core\Controller\Controller;
class Products extends Controller
{
    public function view() {  
        $this->set('foo', 'bar');
    }
}

and

<?php defined('C5_EXECUTE') or die(_("Access Denied."));
    echo $foo; 
?>

I believe the namespacing in the controller page is fine but it seems that the view() method (or whatever other methods I tried) aren't. I get the following error:

Call to undefined method Application\Controller\SinglePage\Products::setupRequestActionAndParameters()

Do you folks have any clues about what going on here? I've spent a few hours already on the docs and the forum and I'm getting nowhere.

Help much appreciated, thanks!

kloport
 
MrKDilkington replied on at Permalink Reply
MrKDilkington
I am interested in reading the comments for this.

I know very little when it comes to single pages/dashboards in 5.7.
mesuva replied on at Permalink Reply
mesuva
When you go to the 'Single Pages' page in the Dashboard, do you see your Products page listed?

If so, have you tried refreshing the page there?
kloport replied on at Permalink Reply
kloport
Yes, I did try to refresh it and the general cache.

I experimented further by adding and removing thing and I now know the controller fires.

The issue rather lies in the class definition. Am I missing something in the line:

class Products extends Controller

?

Thanks community
kloport replied on at Permalink Reply
kloport
Ok, actually the class definition is fine too and the on_start() method I've added as well.

<?php namespace Application\Controller\SinglePage;
use \Concrete\Core\Controller\Controller;
class Products extends Controller {
   function on_start() {
   echo 'started!'; 
   }   
}


What triggers the error is the view() method. Am I supposed to reference a core View method and then use it? I've never seen an example where it was made so.

I am still stuck.
Thank you
mesuva replied on at Permalink Best Answer Reply
mesuva
I've only created single pages for the Dashboard in 5.7, so I'm sort of guessing a bit here, but from looking at how the controllers in /concrete/controllers/single_page are setup, do you need to try extending PageController instead of just Controller?
kloport replied on at Permalink Reply
kloport
You are right my friend. It works.
So to make sure your single page and its controller work in C57, you'll need to have something along the following lines:

Controller:
<?php namespace Application\Controller\SinglePage;
use \Concrete\Core\Page\Controller\PageController;
class Products extends PageController {
   public function on_start() {
      echo 'Products Controller started.';
   }
   public function view() {
      $status = 'started'; 
       $this->set('status', $status);
   }
}

Single Page:
<?php defined('C5_EXECUTE') or die(_("Access Denied."));
    echo $status; 
?>


Thank you very much Hewitt. Keep up the good (community) work!