Dashboard Single Page -> Sub-page blank

Permalink
Hi all
In a package, I have a Dashboard Single Page, which is just working fine.
The controller is here:
/packages/package_handle/controllers/single_page/dashboard/my_single_page.php

The page is here:
/packages/package_handle/single_pages/dashboard/my_single_page.php


So far so good:
The "Main" Single Page Controller is as follows:
namespace Concrete\Package\PackageHandle\Controller\SinglePage\Dashboard;
//...
class MySinglePage extends DashboardPageController {
//...
    public function view() {
       $theSome = 'working great!';
       $this->set('some_stuff', $theSome);
    }
//...
}

As I said, working fine.

Now I wanted to create a sub-page (Settings-Page).
I added a new controller under:

/packages/package_handle/controllers/single_page/dashboard/settings/my_single_page_settings.php

And the Sub-Page under:
/packages/package_handle/single_pages/dashboard/settings/my_single_page_settings.php



As I read (at sooo many places now), the Controller for the Sub-Page must be in a subfolder as described above.
The controller is as follows:
namespace Concrete\Package\PackageHandle\Controller\SinglePage\Dashboard;
//...
class MySinglePageSettings extends DashboardPageController {
//...
    public function view() {
       $theSettingSome = 'NOT working AT ALL!';
       $this->set('some_setting_stuff', $theSettingSome);
    }
//...
}

The package controller installer method:
public function install()
    {
        $pkg = parent::install();
        SinglePage::add('/dashboard/newsletter/settings', $pkg);
    }
I also tried like this: (as mentioned somewhere)
public function install()
    {
        $pkg = parent::install();
        SinglePage::add('/dashboard/newsletter', $pkg);
        SinglePage::add('/dashboard/newsletter/settings', $pkg);
    }

but that just gives me my Single Page and an empty one. The sub-page is still empty though.

Now the sub-page is shown at the right dashboard bar, but its completely blank, just an empty body!
I'm on it for 2 days now and I don't get it!! PLEASE HELP!

daenu
 
hutman replied on at Permalink Reply
hutman
It looks like there are a couple of things here. If you have your new single page at /dashboard/newsletter/settings then you need your controller at

/packages/package_handle/controllers/single_page/dashboard/newsletter/settings.php


and your single page at

/packages/package_handle/single_pages/dashboard/newsletter/settings.php


which should start with

namespace Concrete\Package\PackageHandle\Controller\SinglePage\Dashboard\Newsletter;
//...
class Settings extends DashboardPageController {


Also, from previous posts it seems that you need to have all of your paths and namespaces correct when the package installs, so if you update these things and it still doesn't work, try uninstalling the package and installing again (a pain, I know).
daenu replied on at Permalink Reply
daenu
Sorry Still no luck, As you already know its a newsletter, not a mysinglepage.... I'll edit my question, if goodnightfirefly's answer doesn't fit either... that'll make things easier
goodnightfirefly replied on at Permalink Best Answer Reply
goodnightfirefly
EDIT: I took too long to type :)

==========================

Your current filename/namespaces would create a new page at

http://yoursite.com/dashboard/settings/my_single_page_settings


but I think you want

http://yoursite.com/dashboard/my_single_page/settings


is that correct?

If so, you just need to change your controller filename to

/packages/package_handle/controllers/single_page/dashboard/my_single_page/settings.php


and your view file to

/packages/package_handle/single_pages/dashboard/my_single_page/settings.php


and finally, updating the controller contents to

namespace Concrete\Package\PackageHandle\Controller\SinglePage\Dashboard\MySinglePage;
//...
class Settings extends DashboardPageController {
//...
daenu replied on at Permalink Reply
daenu
goodnightfirefly, YOU ARE THE CHIEF!!!! Now it's logic that a subpage must be in the "subpage" namespace too...
daenu replied on at Permalink Reply
daenu
Now if I want to add another single page at the same level like the settings page. Think the namespaces are ok, but the problem is in the installer method of the package:
public function install()
    {
        $pkg = parent::install();
        // If I do this, the settings page is installed, but not the newsletter_sent page
        SinglePage::add('/dashboard/newsletter/settings', $pkg);
        // If I do this, I get another newsletter "folder"
        SinglePage::add('/dashboard/newsletter/newsletter_sent/', $pkg);
        // If I do this, I get just the newsletter without sub-pages
        SinglePage::add('/dashboard/newsletter', $pkg);

The settings class
namespace Concrete\Package\DanielGasserComNewsLetter\Controller\SinglePage\Dashboard\Newsletter;
The settings controller path:
/packages/daniel_gasser_com_news_letter/controllers/single_page/dashboard/newsletter/settings.php

The newsletter_sent class:
namespace Concrete\Package\DanielGasserComNewsLetter\Controller\SinglePage\Dashboard\Newsletter;
and the path to it:
/packages/daniel_gasser_com_news_letter/controllers/single_page/dashboard/newsletter/newsletter_sent.php

Any ideas?
goodnightfirefly replied on at Permalink Reply
goodnightfirefly
Does your newsletter_sent.php controller have a class name of NewsletterSent with a view() method?
daenu replied on at Permalink Reply
daenu
Yes it has, the page itself is running but at the wrong place:
Newsletter
-->settings
Newsletter
-->newsletter sent

instead of:
Newsletter
-->settings
-->newsletter sent


because of the installer (I suppose)
public function install()
    {
        $pkg = parent::install();
        SinglePage::add('/dashboard/newsletter/settings', $pkg);
        SinglePage::add('/dashboard/newsletter/newsletter_sent', $pkg);
goodnightfirefly replied on at Permalink Reply
goodnightfirefly
Ah I see what you mean now about 'another newsletter folder'. I believe it is because the system is trying to add a 'newsletter' single page but it already exists.

If you look in the Dashboard > Pages & Themes > Single Pages you should see both 'Newsletter' pages, but one has the path of /newsletter while the other one has /newsletter1. (I'm just going by memory for that so I could be wrong).

C5 member jordanlev has created a boilerplate package that has many useful helper methods, one of them being this method which only adds single pages if they don't already exist: (https://github.com/jordanlev/c5_boilerplate_crud/blob/master/package... )

Try adding that getOrAddSinglePage() method to your package controller and adding single pages like this:

$this->getOrAddSinglePage($pkg, '/dashboard/newsletter/newsletter_sent', 'Newsletter Sent');


You may have to rearrange your code a little, notice that you need the
$pkg = parent::install();
in order to pass $pkg to the
$this->installOrUpgrade($pkg);
but follow along with the code and you should be able to work it out :)

Also note that package is for 5.6, so you will need to add

use Page;
use SinglePage;


Post back if you hit any roadblocks and we will go from there
daenu replied on at Permalink Reply
daenu
Thx for this, but it does the same thing as before...
Newsletter/dashboard/newsletter-3
Newsletter/dashboard/newsletter-4
Settings/dashboard/newsletter-4/settings
Newsletter/dashboard/newsletter-5
Newsletter sent/dashboard/newsletter-5/newsletter_sent

And here's the one from jordanlev:
private function installOrUpgrade($pkg) {
        $this->getOrAddSinglePage($pkg, '/dashboard/newsletter', 'Newsletter');
        $this->getOrAddSinglePage($pkg, '/dashboard/newsletter/settings', 'Settings');
        $this->getOrAddSinglePage($pkg, '/dashboard/newsletter/newsletter_sent', 'Newsletter sent');
    }

The 'getOrAddSinglePage' I took as it is from the repostiory. What am I missing?
daenu replied on at Permalink Reply
daenu
I had some entries in the table "PagePaths" like newsletter-1, newsletter-2 and so on, that is why it wasn't working, thx you once again goodnightfirefly
goodnightfirefly replied on at Permalink Reply
goodnightfirefly
Excellent! Glad you have it working :)
daenu replied on at Permalink Reply
daenu
It's going to be a nice little package BTW. I'll add credits at your name ;-)