cake phptutorial

  • 673 views
Uploaded on

tutorial about cake php

tutorial about cake php

More in: Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
673
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
21
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. CakePhp Tutorial By, Swathi Vegesna
  • 2. MVC architectureIsolates domain logic from the GUI
  • 3. Basics of CakePhp• Folder Structure – App • Config : all configuration files • Models : application’s models, data sources and behaviors • Controllers : application’s controllers and components • Views : presentational files • Vendors : 3rd party classes or libraries • Webroot: acts as document root for the application • Locale : stores string files for internationalization • Tmp : stores temporary data • Plugins : plugin packages – Cake – Vendors
  • 4. • Naming conventions – Class name :MyFirstClass filename : my_first_name.php – Classname: Book tablename : books – Classname: BooksController Ex: Database table : books Model class : Book Controller class : BooksController View found at : /app/views/books/index.ctp
  • 5. Steps• Creating the database• Creating a model• Creating a controller• Creating the views
  • 6. Creating the database• Create a new table (name should be according to the naming conventions)• Enter the data.• (Using phpmyadmin)
  • 7. Creating a model• Separates the domain logic from presentation isolating the application logic.• Extends AppModel (extends Model)• Contains data validation rules, association information and methods specific to the table it uses.• For complete reference http://api.cakephp.org• Cakephp dynamically creates a model object class Book extends AppModel { var $name = ‘Book; }• We do can add some behaviors to each model.
  • 8. Creating a controller• Manages the logic for a part of our application• Can access the model object by $this->Book class BooksController extends AppController { var $name = Books; function index() { $this->set(books, $this->Book->find(all)); } }• $this->loadModel(‘Article); loads a different model• Components (packages of logic that are shared between controllers)
  • 9. Creating the views• Layouts (placed in /app/views/layouts)• Elements (reusable parts)• Helpers (var $helpers = array(Form, Html, Javascript, Time);)
  • 10. Sample model <?php class Book extends AppModel{ var $name = Book; var $validate = array( title => array( rule => notEmpty ), author => array( rule => notEmpty ) );}?>
  • 11. Sample Controller<?php class BooksController extends AppController { var $name = Books; var $helpers = array(Html,Ajax,Javascript); function index() { $this->set(books, $this->Book->find(all)); } function view($id = null) { $this->Book->id = $id; $this->set(book, $this->Book->read()); print_r($this->viewVars); }}
  • 12. Sample view<h1>Books</h1><table> <tr> <th>Id</th> <th>Title</th> <th>Author</th> </tr> <?php foreach ($books as $book: ?> <tr> <td><?php echo $book*‘Book+*id+; ?></td> <td> <?php echo $html->link($book*‘Book+*title+,array(controller => ‘books’, action => view, $book*‘Book+*id+)); ?> </td> <td><?php echo $book*‘Book+*‘author+; ?></td> </tr> <?php endforeach; ?></table>
  • 13. References• http://book.cakephp.org/view/4/Beginning- With-CakePHP