I'm developing a site with friendly urls like that:
you are trying to build friendly URLs, but it's too much (and not
It's always better to use
can i change the template inside an action?
yes, you can do it with following and it calls corresponding render method:
$this->setView('blog / post / section / whatever')
be always sure that you are setting another view in action method
Last edited by GEpic (2017-02-21 00:59)
IMHO you are looking in wrong direction. You need to implement this in routing (determine which url run which Presenter:Action) and not switching template.
The problem is that @blashstar wants simple route likes this for everything, then probably look up database for record with that slug with additional information what record type (blog, section, new, etc.) it is and with this information set another view.
$router = new Route('<slug>', 'Homepage:default');
That's really bad idea (described above) and can be done nicer, but there is a solution for what he wants.
Last edited by GEpic (2017-02-21 16:37)
I got that, but then he just needs to create his route (class implementing IRouter) and there in match method define which presenter should be called. This problem has to be solved on routing level and not like this.
But then you must call database on routing level, cause the slugs will be the same for all the posts / pages / etc., don't know what's better atm. :/
If you have 10 static pages, then you can write them into the router directly.
But if sections / blog / etc. is created dinamically, then you have no other options.
Last edited by GEpic (2017-02-22 00:34)
- Member | 140
Calling database on routing level is absolutely fine and in fact I prefer that. But if you really want – there is another approach for inspiration. It's maybe three years old, but it still works in production.
It works only with this simple route rule. Nowadays I would implement it directly in the router but it may be quite complicated especially for newcomers.