I am new to symfony. As an exersice I`m trying to make some basic cms.And I was wondering is this aproach of routing wrong:
/**
* @Route("/back-office/", name="back-office")
*/
public function indexAction(Request $request,$page="")
{
switch($page){
case "":
return $this->render('CmsBundle:BackOffice:index.html.twig');
break;
default:
return $this->render('CmsBundle:BackOffice:site-map.html.twig');
break;
}
}
This is my yaml confing:
back_office_pages:
path: /{page}
defaults: { _controller: CmsBundle:BackOffice:index}
By using this aproach I wont have to configure each route in the yaml file. Since routes may vary. But I am not quite sure this is the symfony way of doing things so I decided to ask for advice..
What I`m trying to achive: Lets say we have a user that have less back-end programing expirience or not at all and he stumbuled upon the CMS. The goal is to add front end pages using some user interface. Then we store the pages(slug) in the database. In the index action we retrive this data. From the database we can also assing template to a page (we need the user to have at least some html+css+twig).
So what we do is get the pages that user added : ex : Gallery, Contacts we check the request url and if the page requested is in the array from the database we return the template related to the page.
NOTE: If you disagree with this method please do not bash me but eplain why is this wrong. Because as I said I am still new with the framework.
path
topage
or vice versa. Also it's better to have one action, one template per page. – Turdaliev Nursultanm trying to figure out why should I have one action per template I mean I do for the clarity of the code of course. But wouldn
t this make it harder to maintain from other point of view each time you are changing a page you have to make the confingurations to the yaml as well. Clearing cache etc. And the goal of this CMS is to have somewhat dynamic template manager. I can write some script that edits the yaml but that sound like security issue to me :). – Newbie