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
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
That's the same error I get. I've tried. Looking in the PageController files for clues but nothing
Anyone able to shed some light in this? It's brought my whole project to a stand still
For reference, this Github discussion and subsequent pull request for 5.5 explain the situation better:https://github.com/concrete5/concrete5/pull/147...
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.
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:
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
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
Great work CrystalShardz!
It's working on my end, I'll put it through its paces today as I continue converting my packages.
It's working on my end, I'll put it through its paces today as I continue converting my packages.
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!
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!
i'll see what I can do :)
i am having the same problem on 5.7.2 and your fix did not work.
It would appear my previous fix for this has been broken by 5.7.1
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)
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)
Still happening on the latest master branch.
I've attached a stripped back package to demonstrate the error.
is the URL, from the members.php controller -> edit() method
I've attached a stripped back package to demonstrate the error.
/dashboard/clan_management/members/edit
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?
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?
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 :(
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 :(
It's possible. I'll add a github issue for it.
Thankyou so much Andrew!
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