Dashboard Controller/View

Permalink 1 user found helpful
So I have made a dashboard Single Page under:

/application/single_pages/dashboard/newsletter.php
and a view.php in the same folder

And a Controller under:

/application/controllers/single_pages/dashboard/newsletter.php

The Controller looks like:

<?php
namespace Concrete\Controller\SinglePage\Dashboard;
use Concrete\Core\Multilingual\Page\PageList;
use \Concrete\Core\Page\Controller\DashboardPageController;
class Newsletter extends DashboardPageController {
    public function view() {
        $testVar = array(
            'one' => 'some',
            'two' => 'value',
            'three' => 'foo',
            'four' => 'bar'
        );
        $this->set('test', $testVar);
    }
}


The /application/single_pages/dashboard/newsletter.php looks like:

<?php defined('C5_EXECUTE') or die("Access Denied.");
echo 'something';
print_r($test);


The /application/single_pages/dashboard/view.php looks like:

<?php defined('C5_EXECUTE') or die("Access Denied.");


THE PROBLEM:
The
$test
doesn't show up in the view. The
echo 'something';
is showing, so basically the page is up and running.
What am I doing wrong?

Update:

Even when creating a package out of it, it doesn't work

daenu
 
maar replied on at Permalink Reply
maar
I have not tested your code, but the first thing that comes in mind is your namespace:
namespace Concrete\Controller\SinglePage\Dashboard;


If I'm not totally wrong and because I see that your path for your files is /application, I think that the namespace should be:
namespace Application\Controller\SinglePage\Dashboard;


I'm struggling with namespaces my selves at the moment, and it seem that I am beginning to understand.
daenu replied on at Permalink Reply
daenu
Thx for Replying.

I wrapped everything up in a package now because somewhere in the forums or docs (don't find it anymore ;-() Andrew Embler sais that's a bug in the version 5.7.3.x and one should wrap it all up in a package. The package installs without errors, but stiil the same. Here are the new pathes & namespaces:

Controller-Path:

/packages/daniel_gasser_com_news_letter/controllers/single_pages/dashboard/newsletter.php


Controller:

namespace Concrete\Package\DanielGasserComNewsLetter\SinglePage\Dashboard
use \Concrete\Core\Page\Controller\DashboardPageController;
class Newsletter extends DashboardPageController {
    public function view() {
        $testVar = array(
            'one' => 'some',
            'two' => 'value',
            'three' => 'foo',
            'four' => 'bar'
        );
        $this->set('test', $testVar);
    }
}
maar replied on at Permalink Reply
maar
Sorry, but I decided to test it, and you are totally right. It does not seem to work. But I am quite sure that the namespace should start with Application.

I will think about this and come back if I find the answer!
andrew replied on at Permalink Reply
andrew
In your controller path you have "single_pages" I believe it should be "single_page"

Sent from my iPhone

> On Apr 25, 2015, at 11:05 AM, concrete5 Community <discussions@concretecms.com> wrote:
daenu replied on at Permalink Reply 1 Attachment
daenu
Thank you for pointing at. I saw that one too last night, but still the same.
also I installed the package on a fresh & clean c5 installation, but still the same...

I attached the package, maybe someone sees the issue, because I really don't get it.
goodnightfirefly replied on at Permalink Reply
goodnightfirefly
The problem is that you have added a single page for the URL 'dashboard/newsletter' but your controller class is named NewsLetter.

A class of NewsLetter (note the camel-case) would correlate to a URL of 'dashboard/news_letter'.

So if you want the URL to remain 'dashboard/newsletter', rename your controller class to Newsletter (title-case), and the controller filename to newsletter.php.

Otherwise if you want the URL to be 'dashboard/news_letter', change the single page setup in your package controller to
SinglePage::add('dashboard/news_letter', $pkg);
and change your single page file to news_letter.php

Uninstall and reinstall your package after you have made your changes.
maar replied on at Permalink Best Answer Reply
maar
Thanks Andrew - you are right.

Here is the paths:

For the controller:
/application/controllers/single_page/dashboard/newsletter.php

And the code for the controller:
<?php
namespace Application\Controller\SinglePage\Dashboard;
use Concrete\Core\Page\Controller\DashboardPageController;
class Newsletter extends DashboardPageController {
    public function view() {
        $testVar = array(
            'one' => 'some',
            'two' => 'value',
            'three' => 'foo',
            'four' => 'bar'
        );
        $this->set('test', $testVar);
    }
}


The path for the single page:
/application/single_pages/dashboard/newsletter.php

And the code for the single page:
<?php defined('C5_EXECUTE') or die("Access Denied.");
/* Dashboard Pane Header */
echo Core::make('helper/concrete/dashboard')->getDashboardPaneHeaderWrapper(t('Newsletter'), false, false, false);
echo 'something';
print_r($test);


It's tested and works as it should
maar replied on at Permalink Reply
maar
Just to mention...

My solution is for the initial question...To get it to work under "/application"

And to remove the doubt that there is a bug in concrete5 5.7. This is tested in version 5.7.3.1 and 5.7.4RC2

Have a nice Sunday...
daenu replied on at Permalink Reply
daenu
maar, Thank you too!
As there were several issues, I'm not sure now which answer to mark as best... I hope you're not offended that I marked goodnightfirefly's answer as the one.
I wish you a pleasent Sunday too!
daenu replied on at Permalink Reply
daenu
THANK YOU!!
goodnightfirefly, you're the chief, I knew it must be something ridiculous....

For others struggling with that. Ther were several issues.
Conclusion:
1. The controller path for this kind of thing is 'single_page' not 'single_pages' (for the single page itself it must be 'single_pages' though)
2. If the controller file has a 'snake_case_name' the class must have a 'CamelCaseName'
3. In that case the single page url must also be snake_case_name then
daenu replied on at Permalink Reply
daenu
Update:
Yes you're right: the namespace was wrong!
Uninstalling the package and adding a dashboard single page as I did in the first try, but this time with your suggestion of the namespace did not do the trick either!

I don't get it!

Isn't c5 complaining if the namespace is wrong?
And, echoing something is working, so why this does happen?

BTW: The namespace was wrong again. Instead of
namespace Concrete\Package\DanielGasserComNewsLetter\SinglePage\Dashboard
it should be
namespace Concrete\Package\DanielGasserComNewsLetter\Controller\SinglePage\Dashboard
but still no luck.
maar replied on at Permalink Reply
maar
I just had a short discussion about this with one of my colleagues. And we just tried a few things with no luck. I think I have to sleep on this, might be better to wrap this around my head tomorrow.
daenu replied on at Permalink Reply
daenu
Yes, that's what I decided too!
I'll go for a walk now... tomorrow is another day
Thx again for the help.