Creating Static Pages in Symfony 1

I am new to symfony and ask simple questions. I am trying to understand a modular system, but I do not understand how I create the actual home page or other pages that are not based on the model from db. For example, a simple page containing static information or a home page that is a combination of information from different models.

Can anyone help?

+5
source share
6 answers

First of all, modules should not be limited to a model from a database. You may have a Foo module that does not use database content and a Bar module that is mainly based on three different models. Separating a module is a way to logically divide your site into manageable sections. For example, an e-commerce site may have a Products module, a Categories module and a Shopping cart module, etc.

Your last sentence can be divided into two parts:

1) Static information can be on any page - if it is suitable for things like "About Us" and "FAQ", etc., I personally prefer to use the "default" or "home" module and create various actions there counterpart:

./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) - ORM ($this->data = MyModel->findByColumn(...) ..). , , , , ( ..). . Symfony.

+4

.

/frontend/config/routing.yml:

page:
  url:   pages/:page
  param: { module: page, action: index }

"" (apps/frontend/modules/page/actions/actions.class.php):

<?php
class pageActions extends sfActions
{
  public function executeIndex()
  {
    $this->page = $this->getRequestParameter("page");
    $this->forward404Unless($this->_partialExists($this->page));
  }

  protected function _partialExists($name)
  {
    $directory = $this->getContext()->getModuleDirectory();
    return (is_readable($directory.DIRECTORY_SEPARATOR."templates".
            DIRECTORY_SEPARATOR."_".$name.".php"));
  }
}

, /page/templates/indexSuccess.php :

<?php include_partial($page); ?>

, , .. apps/frontend/modules/page/templates/_home.php, http://yousite/pages/home ( )

+4

, . static , . , , .

IMHO , Symfony .

, ( ) static:

class staticActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    if(!$request->hasParameter('site')) {
        return sfView::ERROR;    
    }
    $this->site = $request->getParameter('site');
  }
}

:

//indexSuccess.php
<?php include_partial($site) ?>

- .

routing.yml :

# static stuff
about:
  url: /about
  param: {module: static, action: index, site: about}

, PHP-.

+3

- :

myStaticPage:
    pattern: /pageName
    defaults:
        _controller: FrameworkBundle:Template:template
        template: MyBundle:Home:pageName.html.twig

, .

+2

, , CMS , , . , , .

0

[pathToYourProjectRoot]/web.

, , [pathToYourProjectRoot]/web/assets/static_html/about.html. http://your.site.com/assets/static_html/about.html.

0

All Articles