Single pages and controllers

Permalink
I was having issues figuring out how pass data between the two.

I'm trying to use this simple test that I found in this thread.

https://www.concrete5.org/community/forums/usage/single-page-view-an...
/var/www/html/concrete5/concrete/single_pages/test.php
<?php 
   echo $myColor;


/var/www/html/concrete5/concrete/controllers/single_page/Test.php

<?php
namespace Application\Controller\SinglePage;
use PageController;
class Test extends PageController {
   public function view(){
         $color=red;
         $this->set('myColor',$color);
   }
}


So when I navigate tohttp://mysite.com/test
I expect to see the word red on the screen but I see nothing. What am I doing wrong?

View Replies:
linuxoid replied on at Permalink Reply
linuxoid
Your single page view file has to be in application/single_page/, your single page controller file has to be in application/controllers/single_page/, e.g.

controller file: application/controllers/single_page/test.php
view file: application/single_pages/test.php

Note the file names must be the same and low case.

AND the single page must be created first:
$this->installSinglePage('/test', t('Test'), $pkg);
    private function installSinglePage($path, $cName, $pkg)
    {
        $page = Page::getByPath($path);
        if (!is_object($page) || $page->isError()) {
            $page = SinglePage::add($path, $pkg);
            $page->update(array(
                'cName' => $cName,
            ));
        }
    }
cwilliams replied on at Permalink Reply
Alright, I've got this working now. So just a follow up question.

If my single page is not in the root directory say mysite.com/departments/subdepartment/app

and the php file for that site is view.php rather then app.php

does the controller stay in application/controllers/single_page/
or application/controllers/single_page/departments/subdepartment/app

and would the namespace be?

Application\Controller\SinglePage\Department\Subdepartment\App;
linuxoid replied on at Permalink Reply
linuxoid
If you want a single page in any other part, simply add all the route parts with '/':

view: application/single_pages/departments/subdepartment/app/department.php
controller: application/controllers/single_page/departments/subdepartment/app/department.php

I don't think you can use view.php for single pages. But try it. The controller then has to be view.php too.

The namespace will be Application\Controller\SinglePage\Department\Subdepartment\App
cwilliams replied on at Permalink Reply
Correct me if I'm wrong but isn't view.php being used in the documentation example?

https://documentation.concrete5.org/developers/working-with-pages/si...


Anyway here is what I have now,
mysite.com/departments/assessor/real_estate/Change_Value_Notices

at directory:
/var/www/html/concrete5/application/single_pages/departments/assessor/real_estate/Change_Value_Notices
I have view.php containting the same code as my above example.

At directory:
/var/www/html/concrete5/application/controllers/single_page/departments/assessor/real_estate/Change_Value_Notices
I have another view.php containing
<?php
namespace Application\Controller\SinglePage\Departments\Assessor\RealEstate\ChangeValueNotices;
use PageController;
class view extends PageController {
   public function view(){
         $color=red;
         $this->set('myColor',$color);
   }
}


This however is not working. I'm not seeing the word red on the page like I was in the previous example.
linuxoid replied on at Permalink Reply
linuxoid
Ok, you can do it this way:

1. Create a single page in Dashboard->Pages & Themes->Single Pages and Add Single Page departments/assessor/real_estate/change_value_notices
2. Create application/controllers/single_page/departments/assessor/real_estate/change_value_notices.php
<?php
namespace Application\Controller\SinglePage\Departments\Assessor\RealEstate;
use Concrete\Core\Page\Controller\PageController;
class ChangeValueNotices extends PageController
{
    public function view()
    {
        $color = 'red';
        $this->set('color', $color);
    }
}

3. Create application/single_pages/departments/assessor/real_estate/change_value_notices/view.php
<?php defined('C5_EXECUTE') or die("Access Denied.");
echo $color;
?>

I use single pages in packages, I guess it's different to using them in Application

PS. BTW you forgot to put red in ' ', it must be $color = 'red'; because red is a string.