phpsymfony1static-pages

Making static pages in Symfony 1


Im new to symfony and have some simple questions. I am trying to understand the module system, but I dont understand how I create the actual homepage or other pages that are not based off of a model from the db. For example, the simple about page that has static info or the homepage that is a combination of a bunch of information from different models.

Can anyone help?


Solution

  • First of all, modules do not have to be restricted to a model from the database. You can have a Foo module which relies on no database content, and a Bar module that is primarily based on 3 different models. The module separation is a way to logically break up your site into manageable sections. Eg an e-commerce site might have a Products module, a Categories module and a Cart module and so on.

    Your last sentence can then be split into 2 parts:

    1) Static information can be on any page - if it's for things like "About us" and "FAQ" etc, I personally tend to use a "default" or "home" module, and create the various actions in there vis:

    ./symfony generate:module appname home

    and

    class homeActions extends sfActions
    {
      public function executeAbout(sfWebRequest $request)
      {
        // ...
      }
    
      public function executeFaq(sfWebRequest $request)
      {
        // ...
      }
    }
    

    with the corresponding template files (aboutSuccess.php, faqSuccess.php).

    2) A page can be comprised of data from many different models - just use your preferred ORM's method of retrieving data and set it to the view ($this->data = MyModel->findByColumn(...) etc). If you mean data from different modules, then you'd probably be better off looking at partials or components for elements of a page that can be used across different modules (navigation etc). See the Symfony docs for more details on these.