Changeset 112
- Timestamp:
- 03/02/07 12:02:08 (2 years ago)
- Files:
-
- wiki/Tutorial.wiki (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
wiki/Tutorial.wiki
r110 r112 19 19 == Download and installation == 20 20 21 We highly recommend you to get the trunk version of Akelos until we hit version 1.0. You need to have installed [http://subversion.tigris.org/ subversion] in order to do this and run the this from your command line:21 We highly recommend you to get the trunk version of Akelos until we hit version 1.0. You need to have installed [http://subversion.tigris.org/ subversion]. You can checkout a working copy of the Akelos source code with the command: 22 22 23 23 {{{ … … 25 25 }}} 26 26 27 If you can t or don’t want to checkout the code from subversion, you can get the [http://www.akelos.org/akelos_framework-dev_preview.tar.gz latest stable version] generated automatically by the Continuous Integration system, and untar it by typing:27 If you can’t or don’t want to checkout the code from subversion, you can get the [http://www.akelos.org/akelos_framework-dev_preview.tar.gz latest stable version] generated automatically by the Continuous Integration system, and untar it by typing: 28 28 29 29 {{{ … … 51 51 }}} 52 52 53 And change the {{{#!/usr/bin/env php}}} at the beginning of these files {{{script/console}}}, {{{script/generate}}}, {{{script/migrate}}}, {{{script/setup}}} and {{{script/test}}}to you php binary path.53 And change the `#!/usr/bin/env php` at the beginning of these files `script/console`, `script/generate`, `script/migrate`, `script/setup` and `script/test` to you php binary path. 54 54 55 55 *Note for Windows users:* You will need to call the scripts from your application directory using the full path to your php.exe file like: … … 70 70 As you might have guessed we go with the first option and will create a linked Akelos application which will only expose the public folder to the world. Changing the Framework paths is really simple in Akelos, all you have to do is define in your configuration file where each component is located, but we will leave this for a future tutorial about designing an application for distributing it. 71 71 72 Assuming you’ve downloaded the framework to {{{HOME_DIR/akelos}}} and that you are inside the {{{akelos}}}directory you will check available options for setting up your new application by running72 Assuming you’ve downloaded the framework to `HOME_DIR/akelos` and that you are inside the `akelos` directory you will check available options for setting up your new application by running 73 73 74 74 ./script/setup -h … … 89 89 }}} 90 90 91 So running this command: (replace {{{/www/htdocs}}} with your web server public path. On some shared server it’s {{{/home/USERNAME/public_html}}})91 So running this command: (replace `/www/htdocs` with your web server public path. On some shared server it’s `/home/USERNAME/public_html`) 92 92 93 93 {{{ … … 105 105 }}} 106 106 107 *Note for Windows users:* A soft link to booklink/public is created only on *NIX systems, so you’ll need to tell your web server where to find the public path for the *booklink* application on your {{{httpd.conf}}}file by adding something like this:107 *Note for Windows users:* A soft link to booklink/public is created only on *NIX systems, so you’ll need to tell your web server where to find the public path for the *booklink* application on your `httpd.conf` file by adding something like this: 108 108 109 109 {{{ … … 149 149 ==== Manual configuration editing ==== 150 150 151 Save the files {{{config/DEFAULT-config.php}}} and {{{config/DEFAULT-routes.php}}} as {{{config/config.php}}} and {{{config/routes.php}}}and edit them following them as needed.152 153 You might also need to set the base rewrite path manually i s you want to be able to use nice URLs by editing the file {{{public/.htaccess}}}and setting RewriteBase like:151 Save the files `config/DEFAULT-config.php` and `config/DEFAULT-routes.php` as `config/config.php` and `config/routes.php` and edit them following them as needed. 152 153 You might also need to set the base rewrite path manually if you want to be able to use nice URLs by editing the file `public/.htaccess` and setting RewriteBase like: 154 154 155 155 {{{ … … 157 157 }}} 158 158 159 After your application has been installed correctly you’ll see a welcome message at http://localhost/booklink. Now you can safely remove the framework setup files ( it won’t be available is you have a {{{/configconfig.php}}} file)159 After your application has been installed correctly you’ll see a welcome message at http://localhost/booklink. Now you can safely remove the framework setup files (they won’t be accessible if a `/config/config.php` file exists) 160 160 161 161 == The booklink database structure == … … 167 167 So you will create the database using an installer in order to distribute the changes you make to the booklink database scheme from time to time. Using _installers_ will also allow you to define your database tables and columns independently from the database vendor. 168 168 169 Now you will create a file named {{{app/installers/booklink_installer.php}}}with the following Installer code169 Now you will create a file named `app/installers/booklink_installer.php` with the following Installer code 170 170 171 171 {{{ … … 204 204 205 205 *BOOKS TABLE* 206 207 206 {{{ 208 207 +--------------+--------------+------+-----+----------------+ … … 218 217 219 218 *AUTHORS TABLE* 220 221 219 {{{ 222 220 +-------+--------------+------+-----+----------------+ … … 248 246 249 247 * *Path:* _/app/controllers/_ 250 * *Class Name:* singular or pural, camel cased, ends in {{{Controller}}}_(AccountController, PersonController)_251 * *File Name:* singular or pural, underscored, ends in {{{_controller}}}_(account_controller.php, person_controller.php)_248 * *Class Name:* singular or pural, camel cased, ends in `Controller` _(AccountController, PersonController)_ 249 * *File Name:* singular or pural, underscored, ends in `_controller` _(account_controller.php, person_controller.php)_ 252 250 253 251 ==== Views ==== … … 274 272 }}} 275 273 276 This will generate a brunch of files and folder with code that really works! , don’t trust me? try it yourself. Point your browser to http://localhost/booklink/author and http://localhost/booklink/books to start adding authors and books. Create some records and come back for an explanation of what is going under the hood.274 This will generate a brunch of files and folder with code that really works!. Don’t trust me? Try it yourself. Point your browser to http://localhost/booklink/author and http://localhost/booklink/books to start adding authors and books. Create some records and come back for an explanation of what is going under the hood. 277 275 278 276 == The Akelos Workflow == 279 277 280 This is a small description of the workflow for a call to the following URL {{{http://localhost/booklink/book/show/2}}}281 282 1. Akelos will break up your request into three parameters according to your {{{/config/routes.php}}}file (more on this later)278 This is a small description of the workflow for a call to the following URL `http://localhost/booklink/book/show/2` 279 280 1. Akelos will break up your request into three parameters according to your `/config/routes.php` file (more on this later) 283 281 * controller: _book_ 284 282 * action: _show_ 285 283 * id: 2 286 1. Once Akelos knows about this request it will look for the file {{{/app/controllers/book_controller.php}}} and if found it will instantiate the class {{{BookController}}}287 1. The controller will look for a model that matches the parameter {{{controller}}} from the request. In this case it will look for {{{/app/models/book.php}}}. If found, it will create an instance of the model on the controller {{{$this->Book}}} attribute. If an {{{id}}} is on the request, it will search into the database for the Book with the id 2 and that will remain on {{{$this->Book}}}288 1. Now it will call the action {{{show}}} from the {{{BookController}}}class if it’s available.289 1. Once the show action has been executed, the controller will look for the view file at {{{/app/views/book/show.tpl}}} and will render the results into the {{{$content_for_layout}}}variable.290 1. Now Akelos will look for a layout named like the controller at {{{/app/views/layouts/book.tpl}}}. If found it will render the layout inserting {{{$content_for_layout}}}content and sending the output to the browser.284 1. Once Akelos knows about this request it will look for the file `/app/controllers/book_controller.php` and if found it will instantiate the class `BookController` 285 1. The controller will look for a model that matches the parameter `controller` from the request. In this case it will look for `/app/models/book.php`. If found, it will create an instance of the model on the controller `$this->Book` attribute. If an `id` is on the request, it will search into the database for the Book with the id 2 and that will remain on `$this->Book` 286 1. Now it will call the action `show` from the `BookController` class if it’s available. 287 1. Once the show action has been executed, the controller will look for the view file at `/app/views/book/show.tpl` and will render the results into the `$content_for_layout` variable. 288 1. Now Akelos will look for a layout named like the controller at `/app/views/layouts/book.tpl`. If found it will render the layout inserting `$content_for_layout` content and sending the output to the browser. 291 289 292 290 This might help you understanding the way Akelos handles your requests, so we are ready to modify the base application. … … 294 292 == Relating Books and Authors == 295 293 296 Now you are going to link *boolink* authors and books (complex associations in upcoming tutorials). In order to achieve this you will use the {{{author_id}}}column you added to your database.294 Now you are going to link authors and books (complex associations in upcoming tutorials). In order to achieve this you will use the `author_id` column you added to your database. 297 295 298 296 So you will need to tell your models how they relate to each other like … … 320 318 }}} 321 319 322 Now that you made the models aware of each other you will need to modify the book controller so it loads the {{{author}}} and the {{{book}}}model instances320 Now that you made the models aware of each other you will need to modify the book controller so it loads the `author` and the `book` model instances 323 321 324 322 _/app/models/author.php_ … … 332 330 }}} 333 331 334 Next step is to show available authors when creating or editing a book. This can be achieved using the {{{$form_options_helper}}} by inserting the following code right after {{{<?=$active_record_helper->error_messages_for('book');?>}}}on the _/app/views/book/_form.tpl_ file332 Next step is to show available authors when creating or editing a book. This can be achieved using the `$form_options_helper` by inserting the following code right after `<?=$active_record_helper->error_messages_for('book');?>` on the _/app/views/book/_form.tpl_ file 335 333 336 334 {{{ … … 343 341 If you have not added authors yet, go and created some right now and then visit http://locahost/boolink/book/add to check out the brand new authors select list. Go ahead and create a new book selecting an author from the list. 344 342 345 Seems like the author has been saved but it its not included on the {{{app/views/book/show.tpl}}} view. You’ll add it this code right after {{{<? $content_columns = array_keys($Book->getContentColumns()); ?>}}}343 Seems like the author has been saved but it its not included on the `app/views/book/show.tpl` view. You’ll add it this code right after `<? $content_columns = array_keys($Book->getContentColumns()); ?>` 346 344 347 345 {{{ … … 349 347 }}} 350 348 351 You must be screaming now about the rare {{{_{Author}}}} and {{{{book.author.name?}}}}syntax. Thats actually [http://www.bermi.org/projects/sintags Sintags] a small set of rules that helps on writing cleaner views and that will be compiled to standard PHP.349 You must be screaming now about the rare `_{Author}` and `{book.author.name?}` syntax. Thats actually [http://www.bermi.org/projects/sintags Sintags] a small set of rules that helps on writing cleaner views and that will be compiled to standard PHP. 352 350 353 351 == Colophon == 354 352 355 This is all for know, I’ll be improving this tutorial from time to time to add some missing features to this and other documents like:353 This is all for now, I’ll be improving this tutorial from time to time to add some missing features to this and other documents like: 356 354 357 355 * validations … … 369 367 370 368 My apologies for any typo or grammatical error you might find. English is not my mother tongue and I would really like you to help me fixing errors in this document. 371 372
