5.7 One Controller, Multiple views

Permalink
So im trying to do what is the same as this post here:http://www.concrete5.org/community/forums/usage/one-controller-for-... but using 5.7

I have tried to implement the solution by Jordan but this does not work in the new 5.7 (or im doing something wrong). Can anyone advise how to get a controller to use multiple view files instead of having one controller for every singlepage

 
goodnightfirefly replied on at Permalink Reply
goodnightfirefly
What is the error you are getting?

I'm also trying to get it working, the error I get trying to use $this->render('example') is

The identifier pTemplateID is missing for a query of Concrete\Core\Page\Template
CrystalShardz replied on at Permalink Reply
That's the same error I get. I've tried. Looking in the PageController files for clues but nothing
CrystalShardz replied on at Permalink Reply
Anyone able to shed some light in this? It's brought my whole project to a stand still
goodnightfirefly replied on at Permalink Reply
goodnightfirefly
For reference, this Github discussion and subsequent pull request for 5.5 explain the situation better:https://github.com/concrete5/concrete5/pull/147...
CrystalShardz replied on at Permalink Reply
Thanks for the link goodnightfirefly I think I may be able to modify the main view controller a bit like in the pull request to do this. I'll upload y modified file(s) if/when I manage to do it.
CrystalShardz replied on at Permalink Reply
OK I think i've managed to crack it.

I've modified the concrete/src/Page/View/PageView.php in the setupRender() function to look like below:

public function setupRender()
    {
        $this->loadViewThemeObject();
        $env = Environment::get();
        if ($this->c->getPageTypeID() == 0 && $this->c->getCollectionFilename()) {
            $cFilename = trim($this->c->getCollectionFilename(), '/');
      /** CrystalShardz Mod BEGIN **/
      $path = ltrim($this->viewPath, '/') . '/' . $this->controller->getAction() . '.php';
      if(file_exists($env->getPath(DIRNAME_PAGES . '/' . $path, $this->c->getPackageHandle()))){
         $cFilename = $path;
      }
      /** CrystalShardz Mod END **/


To use:
With Items as my controller name i would create the path:
{Package Root}/single_pages/dashboard/multi_view/items
within my package and in here id put my actions (add.php edit.php delete.php item.php)

hope this helps
goodnightfirefly replied on at Permalink Reply
goodnightfirefly
Great work CrystalShardz!

It's working on my end, I'll put it through its paces today as I continue converting my packages.
goodnightfirefly replied on at Permalink Reply
goodnightfirefly
I hit a snag in my testing, take a look at this method on line 37 (it should be highlighted) for an example use case:https://github.com/jordanlev/c5_boilerplate_crud/blob/master/package...

With the proposed patch it would attempt to render a 'duplicate.php' template, and not the edit.php as needed.

For method_name()-to-method_name.php though, it works great!
CrystalShardz replied on at Permalink Reply
i'll see what I can do :)
aryeh replied on at Permalink Reply
i am having the same problem on 5.7.2 and your fix did not work.
CrystalShardz replied on at Permalink Reply
It would appear my previous fix for this has been broken by 5.7.1
andrew replied on at Permalink Reply
andrew
I've seen that error before, but I'm actually having trouble reproducing
this. Can you verify it's still a problem and under what conditions it
occurs? For example, I'm using $this->render(/path/to/view) from within a
controller method without any problems.

You can see it working in
\Concrete\Core\Page\Controller\PublicProfilePageController – if a config
value isn't set a certain way we render a particular view instead.

Apologies if there's another use case that I'm missing that's still broken. (Also, FYI – I'm using the latest version from GIthub)
goodnightfirefly replied on at Permalink Reply 1 Attachment
goodnightfirefly
Still happening on the latest master branch.

I've attached a stripped back package to demonstrate the error.

/dashboard/clan_management/members/edit
is the URL, from the members.php controller -> edit() method
andrew replied on at Permalink Reply
andrew
Ah, I see. The problem in this case is the members/edit is not a single page. The render() method now needs the path that is sent to it to be a single page. This may not be quite as convenient, as I can recognize that there are times when it's nicer to just have some views in your package and render them without worrying how they'll act if they get navigated to as pages. But without this actually being a single page, we don't know where to actually look for the /dashboard/clan_management/members/edit.php view, since we don't have a record if it being the in the database as part of a particular package ID.

Is there a reason why you couldn't just create a dashboard/clan_management/members/edit.php single page and controller, and make the edit() method that you have in your current members.php controller the view() method in the edit controller?
goodnightfirefly replied on at Permalink Reply
goodnightfirefly
https://github.com/concrete5/concrete5/pull/147#issuecomment-2314778

Can the above pull request not be ported to 5.7? That PR is what this whole discussion is based on, I just want to make sure we are on the same page.

You said "that totally makes sense" back then in 2011, I am confused a bit that we might have to go back to 1:1 mapping a controller to a single page :(
andrew replied on at Permalink Reply
andrew
It's possible. I'll add a github issue for it.
goodnightfirefly replied on at Permalink Reply
goodnightfirefly
Thankyou so much Andrew!