Development

Changeset 6465

You must first sign up to be able to contribute.

Changeset 6465

Show
Ignore:
Timestamp:
12/11/07 20:12:25 (1 year ago)
Author:
fabien
Message:

doc: updated the first tutorial for symfony 1.1 (work in progress)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • doc/trunk/tutorial/my-first-project.txt

    r6404 r6465  
    6969This schema describes the structure of two the tables needed for the weblog. `Post` and `Comment` are the names of the related classes to be generated. Save the file, open a command line, browse to the `sf_sandbox/` directory and type: 
    7070 
    71     $ php symfony propel-build-model 
     71    $ php symfony propel:build-model 
    7272 
    7373>**Note**: Make sure to be at the root of your project (`sf_sandbox/`) when you call the `symfony` command. 
     
    7777Now type in the command line: 
    7878 
    79     $ php symfony propel-build-sql 
     79    $ php symfony propel:build-sql 
    8080 
    8181A `lib.model.schema.sql` file is created in `sf_sandbox/data/sql/`. This SQL query can be used to initialize a database with the same table structure. You could create a database in MySQL with the command line or a web interface (as described in the [model chapter](http://www.symfony-project.com/book/trunk/08-Inside-the-Model-Layer)). Luckily, the symfony sandbox is configured to work out of the box with a simple SQLite file, so no database initialization is required. By default, the `sf_sandbox` project will use a database called `sandbox.db` located in `sf_sandbox/data/`. To build the table structure based on the the SQL file, type: 
    8282 
    83     $ php symfony propel-insert-sql 
    84  
    85 >**Note**: Don't worry if there is a warning at that point, it is normal. The `insert-sql` command removes existing tables before adding the ones of your `lib.model.schema.sql`, and there is no table to remove at that time. 
     83    $ php symfony propel:insert-sql 
     84 
     85>**Note**: Don't worry if there is a warning at that point, it is normal. The `propel:insert-sql` command removes existing tables before adding the ones of your `lib.model.schema.sql`, and there is no table to remove at that time. 
    8686 
    8787Create the application scaffolding 
     
    9090The basic features of a weblog are to be able to Create, Retrieve, Update and Delete (CRUD) posts and comments. As you are new to symfony, you will not create symfony code from scratch, but rather let it create a scaffolding that you may use and modify as needed. Symfony can interpret the data model to generate the CRUD interface automatically: 
    9191 
    92     $ php symfony propel-generate-crud frontend post Post 
    93     $ php symfony propel-generate-crud frontend comment Comment 
    94     $ php symfony clear-cache 
     92    $ php symfony propel:generate-crud frontend post Post 
     93    $ php symfony propel:generate-crud frontend comment Comment 
     94    $ php symfony cache:clear 
    9595 
    9696    On *nix systems, you will have to change some rights: 
     
    111111>**Note**: In the URLs above, the name of the main script - called *front controller* in symfony - was changed from `index.php` to `frontend_dev.php`. The two scripts access the same application (`frontend`), but in different environments. With `frontend_dev.php`, you access the application in the **development environment**, which provides handy development tools like the debug toolbar on the top right of the screen and the live configuration engine. That's why the processing of each page is slower than when using `index.php`, which is the front controller of the **production environment**, optimized for speed. If you want to keep on using the production environment, replace `frontend_dev.php/` by `index.php/` in the following URLs, but don't forget to clear the cache before watching the changes: 
    112112> 
    113 >     $ php symfony clear-cache 
     113>     $ php symfony cache:clear 
    114114>      
    115115>     http://localhost/sf_sandbox/web/index.php/ 
     
    160160The home page itself needs to be changed. It uses the default template of the `default` module, which is kept in the framework but not in your application directory. To override it, you have to create a custom `main` module: 
    161161 
    162     $ php symfony init-module frontend main 
     162    $ php symfony generate:module frontend main 
    163163 
    164164By default, the `index` action shows a default congratulations screen. To remove it, edit the `sf_sandbox/apps/frontend/modules/main/actions/actions.class.php` and remove the content of the `executeIndex()` method as follows: 
     
    273273 
    274274    [php] 
    275     public function executeUpdate (
    276     { 
    277       if (!$this->getRequestParameter('id', 0)) 
     275    public function executeUpdate($request
     276    { 
     277      if (!$request->getParameter('id')) 
    278278      { 
    279279        $comment = new Comment(); 
     
    281281      else 
    282282      { 
    283         $comment = CommentPeer::retrieveByPk($this->getRequestParameter('id')); 
     283        $comment = CommentPeer::retrieveByPk($request->getParameter('id')); 
    284284        $this->forward404Unless($comment); 
    285285      } 
    286286 
    287       $comment->setId($this->getRequestParameter('id')); 
    288       $comment->setPostId($this->getRequestParameter('post_id')); 
    289       $comment->setAuthor($this->getRequestParameter('author')); 
    290       $comment->setEmail($this->getRequestParameter('email')); 
    291       $comment->setBody($this->getRequestParameter('body')); 
     287      $comment->setId($request->getParameter('id')); 
     288      $comment->setPostId($request->getParameter('post_id')); 
     289      $comment->setAuthor($request->getParameter('author')); 
     290      $comment->setEmail($request->getParameter('email')); 
     291      $comment->setBody($request->getParameter('body')); 
    292292 
    293293      $comment->save(); 
     
    390390 
    391391    [php] 
    392     public function executePermalink(
     392    public function executePermalink($request
    393393    { 
    394394      $posts = PostPeer::doSelect(new Criteria()); 
    395       $title = $this->getRequestParameter('title'); 
     395      $title = $request->getParameter('title'); 
    396396      foreach ($posts as $post) 
    397397      { 
     
    403403      $this->forward404Unless($post); 
    404404 
    405       $this->getRequest()->setParameter('id', $post->getId()); 
     405      $request->setParameter('id', $post->getId()); 
    406406 
    407407      $this->forward('post', 'show'); 
     
    463463For you to write posts, let's create a backend application by typing in the command line (still from the `sf_sandbox` project directory): 
    464464 
    465     $ php symfony init-app backend 
    466     $ php symfony propel-init-admin backend post Post 
    467     $ php symfony propel-init-admin backend comment Comment 
    468      
     465    $ php symfony generate:app backend 
     466    $ php symfony propel:init-admin backend post Post 
     467    $ php symfony propel:init-admin backend comment Comment 
     468 
    469469This time, we use the [admin generator](http://www.symfony-project.com/book/trunk/14-Generators). It offers much more features and customization than the very basic CRUD generator. 
    470470 
     
    545545But the logging action doesn't exist! Ok, so you can easily add it. First, create the `security` module skeleton: 
    546546 
    547     $ php symfony init-module backend security 
     547    $ php symfony generate:module backend security 
    548548 
    549549This new module will be used to handle the login form and the request. Edit the `apps/backend/modules/security/templates/indexSuccess.php` to create the login form: 
     
    569569 
    570570    [php] 
    571     public function executeLogin(
    572     { 
    573       if ($this->getRequestParameter('login') == 'admin' && $this->getRequestParameter('password') == 'password') 
     571    public function executeLogin($request
     572    { 
     573      if ($request->getParameter('login') == 'admin' && $request->getParameter('password') == 'password') 
    574574      { 
    575575        $this->getUser()->setAuthenticated(true); 
     
    579579      else 
    580580      { 
    581         $this->getRequest()->setError('login', 'incorrect entry'); 
     581        $request->setError('login', 'incorrect entry'); 
    582582 
    583583        return $this->forward('security', 'index');