Single page controller

Hello everybody,
I’m desperately trying to create a single page with a controller as instructed in the documentation.

The single page has been added via the dashboard and my theme view.php template has been created. All works perfectly so far, I can display the content of my single page view file.
I’m facing a problem with the controller which is totally ignored.

Here is the tree structure for my single page

The controller code from application/single_pages/mypage.php

namespace Application\Controller\SinglePage\Mypage;
use Concrete\Core\Page\Controller\PageController;

class Mypage extends PageController
	public function view()
		$this->set('myVar','this var value is sent via the controller');

The code from application/single_pages/mypage/mypage.php

echo $myVar;
echo 'Some content';

I can’t send data from the controller to the page view.

Whoops \ Exception \ ErrorException (E_WARNING)
Undefined variable $myVar

I can’t figure out what I am doing wrong :frowning_face:
Thank you in advance for your precious help.

First step is to confirm you controller is actually running. You can do that by temporarily inserting something like the below into the view() method of the controller :


I usually do everything in packages so the next advice could be wrong.

Looking at your code, I suspect the controller needs to be in application/controllers/single_page/… etc. Note the plural ‘controllers’ and singular ‘single_page’

1 Like

The first line of all my single page controllers doesn’t have the \Mypage bit at the end. Here’s the first few lines of one of them:

namespace Application\Controller\SinglePage;
use PageController;
use Database;
use Page;

class AdminSchedule extends PageController

1 Like

As @JohntheFish said your controller needs to live in application/controllers/single_page/mypage.php

As @mhawke said your namepace should not contain the class name, it should be Application/Controller/SinglePage.

Once you have those changed you need to go into Dashboard → Single Pages and push the refresh doodad next to your single page so that the controller gets recognized (if this doesn’t work delete it and re-add).

1 Like

@JohntheFish , @mhawke and @hutman
Sorry for my late reply, I was busy on other projects.
I followed your instructions and everything is working fine now.
Thanks you for having taken time to solve my problem :pray: