I’m very new into PHP frameworks and Symfony and I already started reading documentation. I’ll begin converting my old codebase after I grasp the basics, but there’s something I don’t understand, hopefully will with your help. I understand that code must be reusable in the PHP part, so please ignore my php code below, I am asking this question about the html (view, right?) part. I’m mainly a front end developer.
I don’t want to use Twig, so I added .php to my config.
Let’s say I have something like this. Where do I put this html code in my symfony app so I could get this page when I call /categories/categoryname ?
I’ve got another question to ask. I created two URL’s, one is to show books, the other one is for book comments.
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class DefaultController extends Controller {
/**
* @Route("/book/{id}", name="book")
*/
public function indexAction($id) {
return $this->render('::default/book.html.php', array(
'id' => $id
));
}
/**
* @Route("/book/comments/{id}", name="bookcomments")
*/
public function showComments($id) {
return $this->render('::default/comment.html.php', array(
'id' => $id
));
}
}
While I use flat PHP, I was creating a different file for each job (book.php, comment.php, etc). I’m still reading the docs, but I wanted to ask this question. Do I need to keep this practice and create a new file for each job under /views or is it a bad practice? I know I need to keep my code clean.