Scaffolding is of great use in the early days of application development. With a single command, symfony creates an entire module based on the description of a given table.

14.2.1. Generating a Scaffolding

To generate the scaffolding for an article module based on the Article model class, type the following:

> symfony propel-generate-crud myapp article Article

Symfony reads the definition of the Article class in the schema.yml and creates a set of templates and actions based on it, in the myapp/modules/article/ directory.

The generated module contains three views. The list view, which is the default view, displays the rows of the blog_article table when browsing to http://localhost/myapp_dev.php/article as reproduced in Figure 14-2.

list view of the article module

Figure 14.2 list view of the article module

Clicking an article identifier displays the show view. The details of one row appear in a single page, as in Figure 14-3.

show view of the article module

Figure 14.3 show view of the article module

Editing an article by clicking the edit link, or creating a new article by clicking the create link in the list view, displays the edit view, reproduced in Figure 14-4.

Using this module, you can create new articles, and modify or delete existing ones. The generated code is a good base for further developments. Listing 14-2 lists the generated actions and templates of the new module.

edit view of the article module

Figure 14.4 edit view of the article module

Listing 14-2 - Generated CRUD Elements, in myapp/modules/article/

// In actions/actions.class.php
index           // Forwards to the list action below
list            // Displays the list of all the records of the table
show            // Displays the lists of all columns of a record
edit            // Displays a form to modify the columns of a record
update 	         // Action called by the edit action form
delete 	         // Deletes a record
create 	         // Creates a new record

// In templates/
editSuccess.php  // Record edition form (edit view)
listSuccess.php  // List of all records (list view)
showSuccess.php  // Detail of one record (show view)

The logic of these actions and templates is quite simple and explicit, and so rather than reproduce and explain it all, Listing 14-3 gives just a sneak peek on the generated action class.

Listing 14-3 - Generated Action Class, in myapp/modules/article/actions/actions.class.php

class articleActions extends sfActions
{
  public function executeIndex()
  {
    return $this->forward('article', 'list');
  }

  public function executeList()
  {
    $this->articles = ArticlePeer::doSelect(new Criteria());
  }

  public function executeShow()
  {
    $this->article = ArticlePeer::retrieveByPk($this->getRequestParameter('id'));
    $this->forward404Unless($this->article);
  }
  ...

Modify the generated code to fit your requirements, repeat the CRUD generation for all the tables that you want to interact with, and you have a basic working application. Generating a scaffolding really bootstraps development; let symfony do the dirty job for you and focus on the interface and specifics.

14.2.2. Initiating a Scaffolding

Initiating a scaffolding is mostly useful when you need to check that you can access the data in the database. It is fast to build and also fast to delete once you're sure that everything works fine.

To initiate a Propel scaffolding that will create an article module to deal with the records of the Article model class name, type the following:

> symfony propel-init-crud myapp article Article

You can then access the list view using the default action:

http://localhost/myapp_dev.php/article

The resulting pages are exactly the same as for a generated scaffolding. You can use them as a simple web interface to the database.

If you check the newly created actions.class.php in the article module, you will see that it is empty: Everything is inherited from an auto-generated class. The same goes for the templates: There is no template file in the templates/ directory. The code behind the initiated actions and templates is the same as for a generated scaffolding, but lies only in the application cache (myproject/cache/myapp/prod/module/autoArticle/).

During application development, developers initiate scaffoldings to interact with the data, regardless of interface. The code is not meant to be customized; an initiated scaffolding can be seen as a simple alternative to PHPmyadmin to manage data.