5.7 One Controller, Multiple views
PermalinkI 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
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
It's working on my end, I'll put it through its paces today as I continue converting my packages.
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!
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)
I've attached a stripped back package to demonstrate the error.
/dashboard/clan_management/members/edit
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?
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 :(
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