Changeset 6465
- Timestamp:
- 12/11/07 20:12:25 (1 year ago)
- Files:
-
- doc/trunk/tutorial/my-first-project.txt (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
doc/trunk/tutorial/my-first-project.txt
r6404 r6465 69 69 This 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: 70 70 71 $ php symfony propel -build-model71 $ php symfony propel:build-model 72 72 73 73 >**Note**: Make sure to be at the root of your project (`sf_sandbox/`) when you call the `symfony` command. … … 77 77 Now type in the command line: 78 78 79 $ php symfony propel -build-sql79 $ php symfony propel:build-sql 80 80 81 81 A `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: 82 82 83 $ php symfony propel -insert-sql84 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. 86 86 87 87 Create the application scaffolding … … 90 90 The 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: 91 91 92 $ php symfony propel -generate-crud frontend post Post93 $ php symfony propel -generate-crud frontend comment Comment94 $ php symfony c lear-cache92 $ php symfony propel:generate-crud frontend post Post 93 $ php symfony propel:generate-crud frontend comment Comment 94 $ php symfony cache:clear 95 95 96 96 On *nix systems, you will have to change some rights: … … 111 111 >**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: 112 112 > 113 > $ php symfony c lear-cache113 > $ php symfony cache:clear 114 114 > 115 115 > http://localhost/sf_sandbox/web/index.php/ … … 160 160 The 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: 161 161 162 $ php symfony init-module frontend main162 $ php symfony generate:module frontend main 163 163 164 164 By 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: … … 273 273 274 274 [php] 275 public function executeUpdate ()276 { 277 if (!$ this->getRequestParameter('id', 0))275 public function executeUpdate($request) 276 { 277 if (!$request->getParameter('id')) 278 278 { 279 279 $comment = new Comment(); … … 281 281 else 282 282 { 283 $comment = CommentPeer::retrieveByPk($ this->getRequestParameter('id'));283 $comment = CommentPeer::retrieveByPk($request->getParameter('id')); 284 284 $this->forward404Unless($comment); 285 285 } 286 286 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')); 292 292 293 293 $comment->save(); … … 390 390 391 391 [php] 392 public function executePermalink( )392 public function executePermalink($request) 393 393 { 394 394 $posts = PostPeer::doSelect(new Criteria()); 395 $title = $ this->getRequestParameter('title');395 $title = $request->getParameter('title'); 396 396 foreach ($posts as $post) 397 397 { … … 403 403 $this->forward404Unless($post); 404 404 405 $ this->getRequest()->setParameter('id', $post->getId());405 $request->setParameter('id', $post->getId()); 406 406 407 407 $this->forward('post', 'show'); … … 463 463 For you to write posts, let's create a backend application by typing in the command line (still from the `sf_sandbox` project directory): 464 464 465 $ php symfony init-app backend466 $ php symfony propel -init-admin backend post Post467 $ php symfony propel -init-admin backend comment Comment468 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 469 469 This 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. 470 470 … … 545 545 But the logging action doesn't exist! Ok, so you can easily add it. First, create the `security` module skeleton: 546 546 547 $ php symfony init-module backend security547 $ php symfony generate:module backend security 548 548 549 549 This 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: … … 569 569 570 570 [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') 574 574 { 575 575 $this->getUser()->setAuthenticated(true); … … 579 579 else 580 580 { 581 $ this->getRequest()->setError('login', 'incorrect entry');581 $request->setError('login', 'incorrect entry'); 582 582 583 583 return $this->forward('security', 'index');