Changeset 7360
- Timestamp:
- 02/06/08 09:21:41 (10 months ago)
- Files:
-
- doc/branches/1.1/tutorial/my-first-project.txt (modified) (16 diffs)
- doc/branches/1.1/tutorial/symfony-ajax.txt (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
doc/branches/1.1/tutorial/my-first-project.txt
r6976 r7360 13 13 14 14 To go fast, we will use the symfony sandbox (you can also download the 15 [final source code](http://www.symfony-project. com/downloads/my_first_project.tgz)).15 [final source code](http://www.symfony-project.org/downloads/my_first_project.tgz)). 16 16 It is an empty symfony project where all the required libraries are already included, 17 17 and where the basic configuration is already done. The great advantage of the sandbox … … 19 19 immediately. 20 20 21 Get it here: [sf_sandbox.tgz](http://www.symfony-project. com/get/sf_sandbox.tgz),21 Get it here: [sf_sandbox.tgz](http://www.symfony-project.org/get/sf_sandbox.tgz), 22 22 and unpack it in your root web directory. Refer to the included `README` file for more 23 23 information. The resulting file structure should look like: … … 54 54 You can also install symfony in a custom folder and setup your web server with 55 55 a Virtual Host or an Alias. The symfony book contains detailed chapters about 56 [symfony installation](http://www.symfony-project. com/book/1.1/03-Running-Symfony)57 and the [symfony directory structure](http://www.symfony-project. com/book/1.1/02-Exploring-Symfony-s-Code).56 [symfony installation](http://www.symfony-project.org/book/1_1/03-Running-Symfony) 57 and the [symfony directory structure](http://www.symfony-project.org/book/1_1/02-Exploring-Symfony-s-Code). 58 58 59 59 Initialize the data model … … 83 83 meaning and tabulations are forbidden, so remember to use spaces for indentation. 84 84 You will find more about YAML and the symfony configuration in the 85 [configuration chapter](http://www.symfony-project. com/book/1.1/05-Configuring-Symfony).85 [configuration chapter](http://www.symfony-project.org/book/1_1/05-Configuring-Symfony). 86 86 87 87 This schema describes the structure of two the tables needed for the blog. … … 99 99 By default, symfony uses the Propel library for this purpose. Theses classes are 100 100 part of the **model** of our application 101 (find more in the [model chapter](http://www.symfony-project. com/book/1.1/08-Inside-the-Model-Layer)).101 (find more in the [model chapter](http://www.symfony-project.org/book/1_1/08-Inside-the-Model-Layer)). 102 102 103 103 Now, we need to convert the schema to SQL statements to initialize the database tables. … … 117 117 Change the DSN argument to match your settings (username, password, host, and database name) 118 118 and then create the database with the command line or a web interface (as described in 119 the [model chapter](http://www.symfony-project. com/book/1.1/08-Inside-the-Model-Layer)).119 the [model chapter](http://www.symfony-project.org/book/1_1/08-Inside-the-Model-Layer)). 120 120 121 121 Now type in the command line: … … 134 134 The `propel:insert-sql` command removes existing tables before adding the ones 135 135 of your `lib.model.schema.sql`, and there is no table to remove at that time. 136 137 As we want to be able to create and edit the blog posts and comments, we also need to 138 generate some forms based on our model schema: 139 140 $ php symfony propel:build-form 141 142 This task generates classes in the `sf_sandbox/lib/form/` directory. 143 These classes are used to manage our model objects as forms. 136 144 137 145 Create the application … … 165 173  166 174 167 Find more about [generators](http://www.symfony-project. com/book/1.1/14-Generators)175 Find more about [generators](http://www.symfony-project.org/book/1_1/14-Generators) 168 176 and the explanation of symfony projects 169 [structure](http://www.symfony-project. com/book/1.1/04-The-Basics-of-Page-Creation)177 [structure](http://www.symfony-project.org/book/1_1/04-The-Basics-of-Page-Creation) 170 178 (project, application, module). 171 179 … … 186 194 > http://localhost/sf_sandbox/web/index.php/ 187 195 188 Find more about [environments](http://www.symfony-project. com/book/1.1/05-Configuring-Symfony#Environments).196 Find more about [environments](http://www.symfony-project.org/book/1_1/05-Configuring-Symfony#Environments). 189 197 190 198 Modify the layout … … 273 281 comment for your this post. 274 282 275 Find more about [views and templates](http://www.symfony-project. com/book/1.1/07-Inside-the-View-Layer).283 Find more about [views and templates](http://www.symfony-project.org/book/1_1/07-Inside-the-View-Layer). 276 284 277 285 Pass data from the action to the template … … 332 340 This is getting good. 333 341 334 Find more about the [naming conventions](http://www.symfony-project. com/book/1.1/07-Inside-the-View-Layer)342 Find more about the [naming conventions](http://www.symfony-project.org/book/1_1/07-Inside-the-View-Layer) 335 343 linking an action to a template. 336 344 … … 410 418 You wanted a blog? You have a blog. 411 419 412 Find more about [actions](http://www.symfony-project. com/book/1.1/06-Inside-the-Controller-Layer).420 Find more about [actions](http://www.symfony-project.org/book/1_1/06-Inside-the-Controller-Layer). 413 421 414 422 Form Validation … … 483 491  484 492 485 Find more about [form validation](http://www.symfony-project. com/book/1.1/10-Forms).493 Find more about [form validation](http://www.symfony-project.org/book/1_1/10-Forms). 486 494 487 495 Change the URL aspect … … 563 571  564 572 565 Find more about [smart URLs](http://www.symfony-project. com/book/1.1/09-Links-and-the-Routing-System).573 Find more about [smart URLs](http://www.symfony-project.org/book/1_1/09-Links-and-the-Routing-System). 566 574 567 575 Cleanup in the frontend … … 602 610 $ php symfony propel:init-admin backend comment Comment 603 611 604 This time, we use the [admin generator](http://www.symfony-project. com/book/1.1/14-Generators).612 This time, we use the [admin generator](http://www.symfony-project.org/book/1_1/14-Generators). 605 613 It offers much more features and customization than the basic CRUD generator. 606 614 … … 751 759  752 760 753 Find more about [security](http://www.symfony-project. com/book/1.1/06-Inside-the-Controller-Layer#Action%20Security).761 Find more about [security](http://www.symfony-project.org/book/1_1/06-Inside-the-Controller-Layer#Action%20Security). 754 762 755 763 Conclusion doc/branches/1.1/tutorial/symfony-ajax.txt
r5696 r7360 5 5 -------- 6 6 7 Symfony has Ajax helpers that make programming an elaborate interface a piece of cake. This tutorial will show you step-by-step how to create an Ajax-powered symfony application in minutes. 7 Symfony has Ajax helpers that make programming an elaborate interface a piece of cake. This tutorial will show you 8 step-by-step how to create an Ajax-powered symfony application in minutes. 8 9 9 10 Introduction 10 11 ------------ 11 12 12 Real lazy folks that can't stand reading long documentation are advised to watch the [online screencast](http://downloads.symfony-project.com/demo/cart/cart.mov) that demonstrates exactly what is written below. 13 14 Adding items to a shopping cart in common e-commerce applications isn't very close to the actual "add to cart" metaphor, since it requires clicking an "add to cart" button, watch a new page (the shopping cart), and then go back to the shop or checkout with buttons. 15 16 Ajax allows to get closer to the cart metaphor, by enabling drag-and-drop interactions and giving immediate visual feedback, without leaving the shop. 17 18 The target application of this tutorial will be a symfony ported version of the shopping cart demo published by [script.aculo.us](http://script.aculo.us/demos/shop) in [Rails](http://www.rubyonrails.com). It uses the [prototype](http://prototype.conio.net/) JavaScript framework (bundled with symfony) and some [script.aculo.us](http://script.aculo.us/) JavaScript that is the core of the JavaScript helpers. 13 Real lazy folks that can't stand reading long documentation are advised to watch the [online 14 screencast](http://www.symfony-project.org/screencast/cart) that demonstrates exactly what is written below. 15 16 Adding items to a shopping cart in common e-commerce applications isn't very close to the actual "add to cart" metaphor, 17 since it requires clicking an "add to cart" button, watch a new page (the shopping cart), and then go back to the shop or 18 checkout with buttons. 19 20 Ajax allows to get closer to the cart metaphor, by enabling drag-and-drop interactions and giving immediate visual 21 feedback, without leaving the shop. 22 23 The target application of this tutorial will be a symfony ported version of the shopping cart demo published by 24 [script.aculo.us](http://script.aculo.us/demos/shop) in [Rails](http://www.rubyonrails.com). It uses the 25 [prototype](http://prototype.conio.net/) JavaScript framework (bundled with symfony) and some 26 [script.aculo.us](http://script.aculo.us/) JavaScript that is the core of the JavaScript helpers. 19 27 20 28 Application Setup … … 30 38 $ symfony init-module app cart 31 39 32 Setup your web server to be able to access this new application (whether using a virtual host or an alias, as described in the [web server setup](http://www.symfony-project.com/cookbook/1_0/web_server) chapter of the documentation). For this example, let's assume that this module is accessible via a localhost: 40 Setup your web server to be able to access this new application (whether using a virtual host or an alias, as described in 41 the [web server setup](http://www.symfony-project.org/cookbook/1_1/web_server) chapter of the documentation). For this 42 example, let's assume that this module is accessible via a localhost: 33 43 34 44 http://localhost/cart/ … … 36 46 Congratulations, it says. 37 47 38 Your app must have access to the symfony JavaScript libraries. If your app doesn't work, check you can access these libraries within your browser (test `http://localhost/sf/prototype/js/prototype.js` for example). If not, you have 3 different ways to fix this problem: 48 Your app must have access to the symfony JavaScript libraries. If your app doesn't work, check you can access these 49 libraries within your browser (test `http://localhost/sf/prototype/js/prototype.js` for example). If not, you have 3 50 different ways to fix this problem: 39 51 40 52 * configure Apache with the following `Alias`: … … 56 68 ------------- 57 69 58 First, you need to create a list of items to be purchased. To keep the project simple, the element list is accessed via a simple `getProducts()` method of the `cart` actions class. The shopping cart is a simple parameter of the `sfUser` object, set with the Attribute [parameter holder](http://www.symfony-project.com/content/book/page/parameter_holder.html). Modify the `sfdemo/apps/app/modules/cart/actions/actions.class.php` to: 70 First, you need to create a list of items to be purchased. To keep the project simple, the element list is accessed via a 71 simple `getProducts()` method of the `cart` actions class. The shopping cart is a simple parameter of the `sfUser` object, 72 set with the Attribute [parameter holder](http://www.symfony-project.org/book/1_1/02-Exploring-Symfony-s-Code#Parameter%20Holders). Modify 73 the `sfdemo/apps/app/modules/cart/actions/actions.class.php` to: 59 74 60 75 [php] … … 73 88 } 74 89 75 The main page of the `cart` module will contain a list of items, and a zone to drag items to. This zone is the shopping cart. So open the template `sfdemo/apps/app/modules/cart/templates/indexSuccess.php` and write in: 90 The main page of the `cart` module will contain a list of items, and a zone to drag items to. This zone is the shopping 91 cart. So open the template `sfdemo/apps/app/modules/cart/templates/indexSuccess.php` and write in: 76 92 77 93 [php] … … 98 114 </div> 99 115 100 You can see that products are shown as images. Use the images available in [this archive](http://www.symfony-project.com/downloads/demo/cart/products.tgz), and put them in the `sfdemo/web/images/` directory. In addition, part of the styling was done for you, so it is recommended that you upload [this stylesheet](http://www.symfony-project.com/downloads/demo/cart/cart.css) to the `sfdemo/web/css/` directory and add a `view.yml` in the `sfdemo/apps/app/modules/cart/config/` directory with the following content: 116 You can see that products are shown as images. Use the images available in [this 117 archive](http://www.symfony-project.org/downloads/demo/cart/products.tgz), and put them in the `sfdemo/web/images/` 118 directory. In addition, part of the styling was done for you, so it is recommended that you upload [this 119 stylesheet](http://www.symfony-project.org/downloads/demo/cart/cart.css) to the `sfdemo/web/css/` directory and add a 120 `view.yml` in the `sfdemo/apps/app/modules/cart/config/` directory with the following content: 101 121 102 122 all: … … 110 130 ----------------- 111 131 112 The cart content will change as you drag items to it. This means that the content of the cart in the template must be in an independent file. Use the `include_partial()` helper for that. The items in the shopping cart will be stored in divs with `float:left` style, so a clearing div is necessary after the container. So change the end of the `indexSuccess.php` template to: 132 The cart content will change as you drag items to it. This means that the content of the cart in the template must be in 133 an independent file. Use the `include_partial()` helper for that. The items in the shopping cart will be stored in divs 134 with `float:left` style, so a clearing div is necessary after the container. So change the end of the `indexSuccess.php` 135 template to: 113 136 114 137 [php] … … 124 147 </div> 125 148 126 The `include_partial()` helper will include a `_cart.php` file, and look for this file in the `sfdemo/apps/app/modules/cart/templates/` directory. Create it with the following content: 149 The `include_partial()` helper will include a `_cart.php` file, and look for this file in the 150 `sfdemo/apps/app/modules/cart/templates/` directory. Create it with the following content: 127 151 128 152 [php] … … 144 168 <?php endif; ?> 145 169 146 If the cart contains items, they appear as images, as many times as they are added; the quantity is be displayed after each series. 170 If the cart contains items, they appear as images, as many times as they are added; the quantity is be displayed after 171 each series. 147 172 148 173 Now watch again the shopping cart at: … … 171 196 <?php endforeach; ?> 172 197 173 This adds a 'draggable' behavior to each of the images of the list of products. The `revert` option will make images go back to their origin position when released (unless received by a receiving element). 174 175 Now, define the cart as a receiving element. You just need to define which part of the template will have to be updated when the event occurs, which action will be called for its content, and which type of draggable elements can be dragged into it. Use the `drop_receiving_elements` JavaScript helper for that: 198 This adds a 'draggable' behavior to each of the images of the list of products. The `revert` option will make images go 199 back to their origin position when released (unless received by a receiving element). 200 201 Now, define the cart as a receiving element. You just need to define which part of the template will have to be updated 202 when the event occurs, which action will be called for its content, and which type of draggable elements can be dragged 203 into it. Use the `drop_receiving_elements` JavaScript helper for that: 176 204 177 205 [php] … … 182 210 )) ?> 183 211 184 Now try again, and move the products to the cart: it works. When a draggable item is dragged to the receiving element, an XMLHTTPRequest is sent to the `add` action, and the result is displayed in the `items` div. The thing is, the `add` action of the `cart` module is not defined yet... 212 Now try again, and move the products to the cart: it works. When a draggable item is dragged to the receiving element, an 213 XMLHTTPRequest is sent to the `add` action, and the result is displayed in the `items` div. The thing is, the `add` action 214 of the `cart` module is not defined yet... 185 215 186 216 Define the Updating Action … … 210 240 This action looks for the parameter sent by the JavaScript (the id of the dragged item) and adds it to the cart. 211 241 212 The result of the `add` action will be the `addSuccess.php` template. It is a simple inclusion of the `_cart.php` partial, but this time it is necessary to pass the products as a parameter : 242 The result of the `add` action will be the `addSuccess.php` template. It is a simple inclusion of the `_cart.php` partial, 243 but this time it is necessary to pass the products as a parameter : 213 244 214 245 [php] 215 246 <?php include_partial('cart', array('products' => $products)) ?> 216 247 217 This template must not use the global layout, so edit the `view.yml` in the `sfdemo/apps/app/modules/cart/config/` directory, and write in: 248 This template must not use the global layout, so edit the `view.yml` in the `sfdemo/apps/app/modules/cart/config/` 249 directory, and write in: 218 250 219 251 addSuccess: … … 229 261 ------------------ 230 262 231 You could stop now, but this shopping cart has a big default: while the cart is updated, the interface doesn't change and the user might be disoriented. This is a general issue of asynchronous requests: an indicator zone has to be added to show that the request is being processed. In addition, nothing tells the user when the dragged item is considered accepted by the cart, so the `hover` style of the `cart` div also has to be defined. 263 You could stop now, but this shopping cart has a big default: while the cart is updated, the interface doesn't change and 264 the user might be disoriented. This is a general issue of asynchronous requests: an indicator zone has to be added to show 265 that the request is being processed. In addition, nothing tells the user when the dragged item is considered accepted by 266 the cart, so the `hover` style of the `cart` div also has to be defined. 232 267 233 268 To do that, edit the `indexSuccess.php` template and write in: … … 240 275 </div> 241 276 242 Save the 'indicator.gif' [image file](http://www.symfony-project.com/downloads/demo/cart/indicator.gif) to your `sfdemo/web/images/` directory. 243 244 Now, modify the `drop_receiving_element()` JavaScript helper call in the same template to show this new indicator while requests are processed and declare the hover style: 277 Save the 'indicator.gif' [image file](http://www.symfony-project.org/downloads/demo/cart/indicator.gif) to your 278 `sfdemo/web/images/` directory. 279 280 Now, modify the `drop_receiving_element()` JavaScript helper call in the same template to show this new indicator while 281 requests are processed and declare the hover style: 245 282 246 283 [php] … … 258 295 ---------- 259 296 260 The complete source of the demo can be [downloaded](http://www.symfony-project.com/downloads/demo/cart/project.tgz) and is available [online](http://www.symfony-project.com/demo/cart.html). You will notice a few minor differences with the code described in this tutorial (including a trash box), but the core behaviors are the same. 261 262 Until the full documentation of the JavaScript helpers is released, you can find more information about them in the [script.aculo.us documentation](http://wiki.script.aculo.us/scriptaculous/list?category=Controls). 297 The complete source of the demo can be [downloaded](http://www.symfony-project.org/downloads/demo/cart/project.tgz) and is 298 available [online](http://www.symfony-project.org/demo/cart.html). You will notice a few minor differences with the code 299 described in this tutorial (including a trash box), but the core behaviors are the same. 300 301 Until the full documentation of the JavaScript helpers is released, you can find more information about them in the 302 [script.aculo.us documentation](http://wiki.script.aculo.us/scriptaculous/list?category=Controls).