Help with controller, views, and a single page plugin

Permalink
I am having a difficult time with a single page plugin when I put my views in sub-folders.

My directory structure is as follows:

[michael@devserver mypackage]$ ls -l
total 132
-rw-rw-r--  1 michael michael   398 Aug 23  2019 composer.json
-rw-rw-r--  1 michael michael 26310 Aug 23  2019 composer.lock
-rw-rw-r--  1 michael michael 11084 Mar  3 16:28 controller.php
drwxrwxr-x  4 michael michael    34 Aug 15  2019 controllers
drwxrwxr-x  2 michael michael   130 Dec 18 12:38 css
-rw-rw-r--  1 michael michael 37721 Aug 19  2019 font-awesome.css
drwxrwxr-x  3 michael michael  4096 Jul 28  2019 images
-rw-rw-r--  1 michael michael   282 Jul 24  2019 INSTALL.TXT
-rw-rw-r--  1 michael michael  3812 Mar  3 17:29 install.xml
drwxrwxr-x  2 michael michael  4096 Mar  2 18:56 js
-rw-rw-r--  1 michael michael   143 Jul 24  2019 LICENSE.TXT
drwxrwxr-x 10 michael michael   154 Jul 28  2019 plugin
-rw-rw-r--  1 michael michael   998 Aug 23  2019 README.md



I have several controllers and views and everything works great:

controllers/single_page/dashboard/mypackage/controller1.php
controllers/single_page/dashboard/mypackage/controller2.php
controllers/single_page/dashboard/mypackage/controller3.php

single_pages/dashboard/mypackage/view1.php
single_pages/dashboard/mypackage/view1a.php
single_pages/dashboard/mypackage/view1b.php
single_pages/dashboard/mypackage/view2.php
single_pages/dashboard/mypackage/view2a.php
single_pages/dashboard/mypackage/view3.php


But then I deside I want to put my views in various subfolders:

single_pages/dashboard/mypackage/bla1/view1.php
single_pages/dashboard/mypackage/bla1/view1a.php
single_pages/dashboard/mypackage/bla1/view1b.php
single_pages/dashboard/mypackage/bla2/view2.php
single_pages/dashboard/mypackage/bla2/view2a.php
single_pages/dashboard/mypackage/bla3/view3.php


But when browsing to a page, I don't get a page not found error but I also don't get any plugin content. Upon investigating, I've found that my controllers are no longer being accessed.

I am thinking it might be related to the Content Interchange Format (CIF) filehttps://documentation.concrete5.org/developers/packages/concrete5-ci... Note sure if the path relates to the controller or the view, and can't find much documentation on this part. I've randomly removed, added, renamed, and just about anything else I can think of but no good.

Any help would be very much appreciated!!!

 
linuxoid replied on at Permalink Reply
linuxoid
Have you installed the single pages in your package during installation?

Here's some info from Documentation:
https://documentation.concrete5.org/developers-guide/working-with-pa...

You can have a look at this free package, see how single pages are installed first [ab_simple_comments\src\SimpleComments\Install\SinglePages.php]:
https://www.concrete5.org/marketplace/addons/free-simple-comments/...
NotionCommotion replied on at Permalink Reply
Yes, I installed the single pages in the package during installation. I also read the documentation you referenced in the first link. It had some cryptic requirements of using plural for some files and singular for others which turned out to be what I was asking about in another posthttps://www.concrete5.org/community/forums/customizing_c5/plural-and... Other parts I really never understood is how files are lowercase and underscores are converted to camelcase classes. Thanks the the link to the sample package, and I will review in detail.

Not positive, but it appears that a controller will not be recognized by Concrete5 unless there is a view with the same filename. Does this jive with your understanding?

Thanks!
linuxoid replied on at Permalink Best Answer Reply
linuxoid
If you really want to know why and how file names align with Classes, pages and all, you have to dive deep into the core code and understand the technologies used. I don't need that to build packages.

But to build your package, just know this:
- namespace Concrete\Package\YourPackageName must be the same as your_package_name
- single page name My Single Page must have a controller class MySinglePage in a file my_single_page.php in your_package_name\controllers\single_page\...
- single page name My Single Page must have a view with the same file name my_single_page.php in your_package_name\single_pages\...
- if you want single pages under another single page (like a folder/node), your need to create folders with the same name as the controller and view files and then to have their controller and view there, e.g.
your_package_name\controllers\single_page\my_single_page.php
your_package_name\controllers\single_page\my_single_page\my_other_page.php
your_package_name\single_pages\my_single_page.php
your_package_name\single_pages\my_single_page\my_other_page.php
- if you want to have only a folder without content and to redirect to a page when clicking on it, create an empty view file with only
<?php defined('C5_EXECUTE') or die("Access Denied.");
?>

and create a controller with a redirect, e.g.
<?php
namespace Concrete\Package\YourPackageName\Controller\SinglePage\Dashboard;
use Concrete\Core\Page\Controller\DashboardPageController;
use Concrete\Core\Routing\Redirect;
class MySinglePage extends DashboardPageController
{
    public function view()
    {
        $r = Redirect::to('/dashboard/my_single_page/my_other_page');
        $r->send();
        exit;        
    }
}

- class name MyClass must be in a file MyClass.php in your_package_name\src\YourClassesFolder\...

NOTE! The single page folder for controllers is called 'single_page' <- singular! But the folder for views is called 'single_pages' <- plural!


Re. "it appears that a controller will not be recognized by Concrete5 unless there is a view with the same filename", yes, the controller and view must be present in the package during the package and single page installation.
NotionCommotion replied on at Permalink Reply
Thank you linuxoid, Your post was VERY helpful. Not only did I read it twice, I printed a hard copy. Yes, I suspected I might need to actually dive deep into the code, but there is so much I really resisted doing so. I understand every word you said exept the following. How does this tie in?

- class name MyClass must be in a file MyClass.php in your_package_name\src\YourClassesFolder\...
linuxoid replied on at Permalink Reply
linuxoid
Regarding the classes, you only need that IF you create your own classes and provide them in the package. You can check the same Simple Comments example package.

If you just make single pages, you don't need that.