SlideShare a Scribd company logo
1 of 40
Download to read offline
CakePHP   Bakery   API   Manual   Forge   Trac




                                  1.2 @ OCPHP
                                                 August 9, 2007




                                                                  © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                              Why CakePHP?
                    MVC architecture
                    Convention over Configuration
                    Flexible and Extensible
                    Write less, do more
                    Open Source, Large Community
                    MIT License

                                                   © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




           CakePHP the right way


                                                             by: Amy Hoy, http://slash7.com/




                                          Think twice, code once
                                               Loose couple


                                                                                           © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                   Hot out of the oven
                          Behaviors              Router

                          “With” Associations    Email

                          Enhanced Validation    Security

                          Forms                  Authentication

                          Pagination             Configure

                          i18n + l10n            Cache Engines

                          Acl                    Console




                                                                  © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                             Behaviors
                    extend models
                    encapsulate reusable functionality
                    use callbacks for automagic




                                                         © 2007 Cake Software Foundation
CakePHP   Bakery   API     Manual   Forge   Trac




                   <?php
                   class CoolBehavior extends ModelBehavior {

                         var $settings = array();

                         function setup(&$model, $config = array()) {
                             $this->settings = $config;
                         }
                         /* Callbacks */
                         function beforeFind(&$model, $query) { }

                         function afterFind(&$model, $results, $primary) { }

                         function beforeSave(&$model) { }

                         function afterSave(&$model, $created) { }

                         function beforeDelete(&$model) { }

                         function afterDelete(&$model) { }

                         function onError(&$model, $error) { }

                         /* Custom Methods */
                         function myCustomMethod(&$model, $data = array()) {
                             return array_merge($model->data, $data);
                         }
                   }
                   ?>
                                                                               © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac



           <?php
           class Post extends AppModel {

                var $actsAs = array(‘Cool’=>array(‘field’=>’cool_id’));

                function doSomething($cool = null) {
                   $this->myCustomMethod(array(‘cool_id’=> $cool));
                }

           }
           ?>

           <?php
           class PostsController extends AppController {
              var $name = ‘Posts’;

                function index() {
                   $this->set(‘posts’, $this->Post->doSomething(5));
                }

           }
           ?>


                                                                         © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                   “With” Associations
                    enables extra fields in join tables
                    access to model for join table

                                                               tags
                   posts                         posts_tag   id
           id                                        s       key
                                                 id
           title                                             name
                                                 post_id
           body                                              created
                                                 tag_id
           created                                           modified
           modified                               date
                                                                      © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                  Adding “With”
                         <?php
                         class Post extends AppModel {

                              var $hasAndBelongsToMany = array(
                         
      
   
   
   
    
  
   
    ‘Tag’ => array(
                         
      
   
   
   
    
  
   
    
     ‘className’ => ’Tag’,
                         
      
   
   
   
    
  
   
    
     ‘with’ => ‘TaggedPost’,
                         	      	   	   	   	    	  	   	    )
                         	      	   	   	   	    	  	   );

                              function beforeSave() {
                                 if(!empty($this->data[‘Tag’])) {
                                       $this->TaggedPost->save($this->data[‘Tag’]);
                                 }
                              }

                         }
                         ?>

                                                                                             © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                    Using “With”
                    <?php
                    class PostsController extends AppController {
                       var $name = ‘Posts’;

                         function tags() {
                            $this->set(‘tags’, $this->Post->TaggedPost->findAll());
                         }
                    }
                    ?>
                    <?php
                      foreach ($tags as $tag) :
                         echo $tag[‘Post’][‘title’];

                           echo $tag[‘Tag’][‘name’];

                           echo $tag[‘TaggedPost’][‘date’];

                         endforeach;
                    ?>
                                                                                     © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                           Validation is King
                   alphaNumeric                  email       number


                   between                       equalTo     numeric


                   blank                         file         phone


                   cc                            ip          postal


                   comparison                    maxLength   ssn


                   custom                        minLength   url


                   date                          money       userDefined


                   decimal                       multiple




                                                                          © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                              Using Validation
             <?php
             class Post extends AppModel {

                   var $validate = array(
                         'title' => array(
                             'required' => VALID_NOT_EMPTY,
                             'length' => array( 'rule' => array('maxLength', 100))
                         ),
                         'body' => VALID_NOT_EMPTY
                      );

             }
             ?>




                                                                                     © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                     Forms made simple
             <?php 

             
      echo $form->create('Post');
                
             
      echo $form->input('title', array('error' => array(
                     
 
     
   
    
      
     
    
     'required' => 'Please specify a valid title',
                     
 
     
   
    
      
     
    
     'length' => 'The title must have no more than 100 characters'
                 
 
    
    
   
    
      
     
    
     )
             	      	   	    	   	    	      	     	    )
             
      
   
    
   
    ); 

             
     echo $form->input('body', array('error' => 'Please specify a valid body'));
             	
             
     echo $form->end('Add');
             ?>




                                                                                                                    © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                         More about Forms
             <?php 
                 /* Change the action */
             
   echo $form->create('User', array(‘action’=> ‘login’));
             ?>

             <?php 
                 /* Change the type for uploading files */
                 echo $form->create('Image', array(‘type’=> ‘file’));
                      echo $form->input('file', array(‘type’=> ‘file’));
                 echo $form->end(‘Upload’);
             ?>


             <?php 
                 /* the three line form */
                 echo $form->create('Post');
                      echo $form->inputs(‘Add a Post’);
                 echo $form->end(‘Add’);
             ?>




                                                                          © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                            Pagination
             <?php
             class PostsController extends AppController {
                var $name = ‘Posts’;

                   var $paginate = array(‘order’=> ‘Post.created DESC’);

                   function index() {
                      $this->set(‘posts’, $this->paginate());
                   }
             }
             ?>
            <?php
            echo $paginator->counter(array(
                'format' => 'Page %page% of %pages%, showing %current% records out of
                %count% total, starting on record %start%, ending on %end%'
            ));
            echo $paginator->prev('<< previous', array(), null, array('class'=>'disabled'));
            echo $paginator->numbers();
            echo $paginator->sort(‘Created’);
            echo $paginator->next('next >>', array(), null, array('class'=>'disabled'));
                                                                                           © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                            i18n/L10n
                    built in gettext for static strings
                    TranslationBehavior for dynamic
                    data
                    console extractor




                                                          © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                      gettext style
          <?php
          /* echo a string */
          __(‘Translate me’);

          /* return a string */
          $html->link(__(‘Translate me’, true), array(‘controller’=>’users’));

          /* by category : LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.*/
          __c(‘Translate me’, ‘LC_CTYPE’);

          /* get plurals by number*/
          __n(‘Translate’, ‘Translates’, 2);

          /* override the domain.*/
          __d(‘posts’, ‘Translate me’);

          /* override the domain by category.*/
          __dc(‘posts’, ‘Translate me’, ‘LC_CTYPE’);


                                                                                                           © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                   Translation Behavior
             <?php
             class Post extends AppModel {

                   var $actsAs = array(‘Translation’=> array(‘title’, ‘body’));

             }
             ?>
                                                             CREATE TABLE i18n_content (
             CREATE TABLE i18n (
                                                             	   id int(10) NOT NULL auto_increment,
             	   id int(10) NOT NULL auto_increment,
                                                             	   content text,
             	   locale varchar(6) NOT NULL,
                                                             	   PRIMARY KEY (id)
             	   i18n_content_id int(10) NOT NULL,
                                                             );
             	   model varchar(255) NOT NULL,
             	   row_id int(10) NOT NULL,
             	   field varchar(255) NOT NULL,
             	   PRIMARY KEY	 (id),
             	   KEY locale	 (locale),
             	   KEY i18n_content_id (i18n_content_id),
             	   KEY row_id	(row_id),
             	   KEY model	 (model),
             	   KEY field (field)
             );



                                                                                                  © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                                 Acl
                    abstracted for maximum
                    compatibility
                    component for controller
                    behavior for model




                                                       © 2007 Cake Software Foundation
CakePHP       Bakery   API   Manual   Forge   Trac




                                          Acl behavior
    <?php                                                          <?php
    class User extends AppModel {                                  class Post extends AppModel {

          var $actsAs = array(‘Acl’=> ‘requester’);                     var $actsAs = array(‘Acl’=> ‘controlled’);

          function parentNode() {}                                      function parentNode() {}

          function bindNode($object) {                                  function bindNode($object) {}
                if (!empty($object['User']['role'])) {
                                                                   }
          	           return 'Roles/' . $object['User']['role'];
                                                                   ?>
                }
          }

          function roles() {
             return $this->Aro->findAll();
          }
    }
    ?>


                                                                                                   © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                                 Routing
                    reverse routes
                    magic variables
                    named parameters
                    parseExtensions
                    REST resource mapping



                                                           © 2007 Cake Software Foundation
CakePHP    Bakery   API   Manual   Forge   Trac




                           Reversing Routes
          <?php
          Route::connect(‘/’, array(‘controller’=>’pages’, ‘action’=>’display’, ‘home’));
          ?>


      <?php
      echo $html->link(‘Go Home’, array(‘controller’=> ‘pages’, ‘action’=> ‘display’, home));
      ?>




                                                                                            © 2007 Cake Software Foundation
CakePHP   Bakery   API    Manual   Forge   Trac




                                   Magic Variables
               	         $Action	 => Matches most common action names

               	         $Year	     => Matches any year from 1000 to 2999

               	         $Month	 => Matches any valid month with a leading zero (01 - 12)

               	         $Day	      => Matches any valid day with a leading zero (01 - 31)

               	         $ID		      => Matches any valid whole number (0 - 99999.....)
                         Router::connect(
                         	   '/:controller/:year/:month/:day',
                         	   array('action' => 'index', 'day' => null),
                         	   array('year' => $Year, 'month' => $Month, 'day' => $Day)
                         );

                         Router::connect(
                         	   '/:controller/:id',
                         
   array('action' => 'index', ‘id’=> ‘1’), array('id' => $ID)
                         );
                                                                                             © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge    Trac




                                      Named Args
                                    http://cakephp.org/posts/index/page:2/sort:title

                                   <?php
                                   class PostsController extends AppController {
                                      var $name = ‘Posts’;

                                          function index() {
                                             $this->passedArgs[‘page’];
                                             $this->passedArgs[‘sort’];
                                          }

                                   }
                                   ?>




                                                                                       © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                         Parsing Extensions
                         /* get everything */
                         Router::parseExtensions();
                         /* more fine grained */
                         Router::parseExtensions(‘xml’, ‘html’);

                         maps views to unique locations
                         http://cakephp.org/posts/index.rss
                          Router::parseExtensions(‘rss’);
                         <?php //app/views/posts/rss/index.ctp
                         	    echo $rss->items($posts, 'transformRSS');
                         	    function transformRSS($post) {
                         	    	      return array(
                         	    	      	     'title'	 	    	     => $post['Post']['title'],
                         	    	      	     'link'	 	     	     => array('url'=>'/posts/view/'.$post['Post]['id']),
                         	    	      	     'description'	      => substr($post['Post']['body'], 0, 200),
                         	    	      	     'pubDate'	 	        => date('r', strtotime($post['Post']['created'])),
                         	    	      );
                         	    }
                         ?>


                                                                                                                     © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                                      Email
                   $this->Email->to = $user['User']['email'];
                   $this->Email->from = Configure::read('Site.email');
                   $this->Email->subject = Configure::read('Site.name').' Password Reset URL';

                   $content[] = 'A request to reset you password has been submitted to '.Configure::read('Site.name');
                   $content[] = 'Please visit the following url to have your temporary password sent';
                   $content[] = Router::url('/users/verify/reset/'.$token, true);

                   if($this->Email->send($content)) {
                   	      $this->Session->setFlash('You should receive an email with further instruction shortly');
                   	      $this->redirect('/', null, true);
                   }


                   /* Sending HTML and Text */
                   $this->Email->sendAs = ‘both’;
                   $this->Email->template = ‘reset_password’;

                   /* HTML templates */
                   //app/views/elements/email/html/reset_password.ctp

                   /* TEXT templates */
                   //app/views/elements/email/text




                                                                                                                      © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                                 Security
                                                 HTTP Auth
                                  <?php
                                  class PostsController extends AppController {
                                     var $name = ‘Posts’;

                                       var $components = array(‘Security’);

                                       function beforeFilter() {
                                          $this->Security->requireLogin(‘add’, ‘edit’, ‘delete’);
                                          $this->Security->loginUsers = array('cake'=>'tooeasy');
                                       }

                                  }
                                  ?>




                                                                                                    © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                  Authentication
                             <?php
                             class PostsController extends AppController {
                                var $name = ‘Posts’;

                                  var $components = array(‘Auth’);

                             }
                             ?>


                              authenticate any model: User, Member, Editor, Contact

                              authorize against models, controllers, or abstract
                              objects

                              automate login




                                                                                   © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual     Forge   Trac




                                            Auth setup
                         <?php
                         class PostsController extends AppController {
                         
      var $name = ‘Posts’;

                         
        var $components = array(‘Auth’);

                         	      function beforeFilter() {
                         	      	      $this->Auth->userModel = 'Member';
                              	       $this->Auth->loginAction = '/members/login';
                         	      	      $this->Auth->loginRedirect = '/members/index';
                         	      	      $this->Auth->fields = array('username' => 'username', 'password' => 'pword');
                         	      	
                         	      	      $this->Auth->authorize = array('model'=>'Member');
                         	      	      $this->Auth->mapActions(array(
                         	      	      	     'read' => array('display'),
                         	      	      	     'update' => array('admin_show', 'admin_hide'),
                         	      	      ));
                         	      	
                         	      }
                         }
                         ?>




                                                                                                                  © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                         Authorize a Model
                     <?php
                     class Member extends Model {
                     	    var $name = 'Member';
                     	
                     	    function isAuthorized($user, $controller, $action) {
                     	
                     	    	    switch ($action) {
                     	    	    	    case 'default':
                     	    	    	    	    return false;
                     	    	    	    break;
                     	    	    	    case 'delete':
                     	    	    	    	    if($user[['Member']['role'] == 'admin') {
                     	    	    	    	    	    return true;
                     	    	    	    	    }
                     	    	    	    break;	 	
                     	    	    }
                     	    }
                     }
                     ?>

                                                                                     © 2007 Cake Software Foundation
CakePHP   Bakery   API    Manual   Forge   Trac




           Authorize a Controller
                     <?php
                     class PostsController extends AppController {
                     
    var $name = ‘Posts’;

                     
      var $components = array(‘Auth’);

                     	      function beforeFilter() {
                     
      
    $this->Auth->authorize = ‘controller’;
                     	      }
                     	
                     	      function isAuthorized() {
                     	      	    if($this->Auth->user('role') == 'admin') {
                     	      	    	    return true;
                     	      	    }
                     	      }
                     }
                     ?>



                                                                              © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                          Authorize CRUD
                           <?php
                           class PostsController extends AppController {
                           
    var $name = ‘Posts’;

                           
      var $components = array(‘Auth’);

                           	      function beforeFilter() {
                           
      
    $this->Auth->authorize = ‘crud’;
                                       $this->Auth->actionPath = 'Root/';
                           	      }
                           }
                           ?>
                           $this->Acl->allow('Roles/Admin', 'Root');
                           $this->Acl->allow('Roles/Admin', 'Root/Posts');




                                                                             © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                            Configure
                   <?php

                   Configure::write(‘Oc.location’, ‘Buddy Group’);

                   Configure::write(‘Oc’, array(‘location’=>‘Buddy Group’));

                   Configure::read(‘Oc.location’);

                   Configure::store('Groups', 'groups',
                                     array('Oc' => array(‘location’=>’Buddy Group’)));

                   Configure::load('groups');

                   ?>




                                                                                         © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge    Trac




                                  Cache Engines
                                    File                          xcache

                                    APC                           Model

                                    Memcache


                             Cache::engine(‘File’, [settings]);

                             $data = Cache::read(‘post’);
                             if(empty($data)) {
                                 $data = $this->Post->findAll();
                                 Cache::write(‘post’, $data);
                             }




                                                                           © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                                 Console
                           Makes writing Command Line
                           Interfaces (CLI) cake
                           Shells
                           Tasks
                           Access to models




                                                           © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                          Core Shells
                                                 Acl
                                                 Extractor
                                                 Bake
                                                 Console
                                                 API



                                                             © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                  The Bake Shell
                                          Tasks

                                                 Model -   cake bake model Post

                                                 Controller - cake bake controller Posts

                                                 View -   cake bake view Posts

                                                 DbConfig -      cake bake db_config

                                                 Project - cake bake project



                            Custom view templates, oh yeah!



                                                                                           © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                              Your Own Shell
                                      <?php
                                      class DemoShell extends Shell {
                                      	
                                      	      var $uses = array('Post');
                                      	
                                      	      var $tasks = array('Whatever', 'Another');
                                      	
                                      	      function initialize() {}
                                      	
                                      	      function startup() {}
                                      	      	
                                      	      function main() {
                                      	      	      $this->out('Demo Script');
                                      	      }
                                      	
                                      	      function something() {
                                      	      	      $this->Whatver->execute();
                                      	      }
                                      	
                                      	      function somethingElse() {
                                          	         $posts = $this->Post->findAll();
                                                    foreach($posts as $post) {
                                                      $this->out(‘title : ‘ . $post[‘Post’][‘title’]);
                                          	         }
                                             }
                                      }
                                      ?>

                                                                                                         © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                                 More....
                                  Xml reading and writing
                                  HttpSockets
                                  Themes
                                  Cookies
                                  ......



                                                            © 2007 Cake Software Foundation
CakePHP   Bakery   API   Manual   Forge   Trac




                                    Questions?




                                                 © 2007 Cake Software Foundation

More Related Content

What's hot

JSP Syntax_1
JSP Syntax_1JSP Syntax_1
JSP Syntax_1brecke
 
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your applicationjavablend
 
Solid principles
Solid principlesSolid principles
Solid principlesSahil Kumar
 
Indic threads pune12-java ee 7 platformsimplification html5
Indic threads pune12-java ee 7 platformsimplification html5Indic threads pune12-java ee 7 platformsimplification html5
Indic threads pune12-java ee 7 platformsimplification html5IndicThreads
 
Testing Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScriptTesting Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScriptMark
 
Inapps Fix Status
Inapps Fix StatusInapps Fix Status
Inapps Fix Statusx
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09Michelangelo van Dam
 
django_reference_sheet
django_reference_sheetdjango_reference_sheet
django_reference_sheetwebuploader
 
Apigility reloaded
Apigility reloadedApigility reloaded
Apigility reloadedRalf Eggert
 
web2py:Web development like a boss
web2py:Web development like a bossweb2py:Web development like a boss
web2py:Web development like a bossFrancisco Ribeiro
 
Chef on Python and MongoDB
Chef on Python and MongoDBChef on Python and MongoDB
Chef on Python and MongoDBRick Copeland
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Michelangelo van Dam
 
Rails vs Web2py
Rails vs Web2pyRails vs Web2py
Rails vs Web2pyjonromero
 
PHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better CodePHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better CodeSWIFTotter Solutions
 
JavaFX – 10 things I love about you
JavaFX – 10 things I love about youJavaFX – 10 things I love about you
JavaFX – 10 things I love about youAlexander Casall
 
JavaFX for Business Application Developers
JavaFX for Business Application DevelopersJavaFX for Business Application Developers
JavaFX for Business Application DevelopersMichael Heinrichs
 

What's hot (20)

JSP Syntax_1
JSP Syntax_1JSP Syntax_1
JSP Syntax_1
 
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application
[Pilarczyk] Adrenaline programing implementing - SOA and BPM in your application
 
429 e8d01
429 e8d01429 e8d01
429 e8d01
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Indic threads pune12-java ee 7 platformsimplification html5
Indic threads pune12-java ee 7 platformsimplification html5Indic threads pune12-java ee 7 platformsimplification html5
Indic threads pune12-java ee 7 platformsimplification html5
 
Testing Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScriptTesting Your JavaScript & CoffeeScript
Testing Your JavaScript & CoffeeScript
 
Inapps Fix Status
Inapps Fix StatusInapps Fix Status
Inapps Fix Status
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09
 
django_reference_sheet
django_reference_sheetdjango_reference_sheet
django_reference_sheet
 
Apigility reloaded
Apigility reloadedApigility reloaded
Apigility reloaded
 
Creating Alloy Widgets
Creating Alloy WidgetsCreating Alloy Widgets
Creating Alloy Widgets
 
web2py:Web development like a boss
web2py:Web development like a bossweb2py:Web development like a boss
web2py:Web development like a boss
 
Chef on Python and MongoDB
Chef on Python and MongoDBChef on Python and MongoDB
Chef on Python and MongoDB
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
Rails vs Web2py
Rails vs Web2pyRails vs Web2py
Rails vs Web2py
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
PHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better CodePHP: 4 Design Patterns to Make Better Code
PHP: 4 Design Patterns to Make Better Code
 
JavaFX – 10 things I love about you
JavaFX – 10 things I love about youJavaFX – 10 things I love about you
JavaFX – 10 things I love about you
 
What's new with PHP7
What's new with PHP7What's new with PHP7
What's new with PHP7
 
JavaFX for Business Application Developers
JavaFX for Business Application DevelopersJavaFX for Business Application Developers
JavaFX for Business Application Developers
 

Viewers also liked

Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.SWAAM Tech
 
How to learn to build your own PHP framework
How to learn to build your own PHP frameworkHow to learn to build your own PHP framework
How to learn to build your own PHP frameworkDinh Pham
 
Php Frameworks
Php FrameworksPhp Frameworks
Php FrameworksRyan Davis
 
Benefits of the CodeIgniter Framework
Benefits of the CodeIgniter FrameworkBenefits of the CodeIgniter Framework
Benefits of the CodeIgniter FrameworkToby Beresford
 
Introduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterIntroduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterPongsakorn U-chupala
 
Introduction Yii Framework
Introduction Yii FrameworkIntroduction Yii Framework
Introduction Yii FrameworkTuan Nguyen
 
Knowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP frameworkKnowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP frameworkBukhori Aqid
 
A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!Muhammad Ghazali
 
PHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterPHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterJamshid Hashimi
 
Laravel 5 In Depth
Laravel 5 In DepthLaravel 5 In Depth
Laravel 5 In DepthKirk Bushell
 
Intro to Laravel PHP Framework
Intro to Laravel PHP FrameworkIntro to Laravel PHP Framework
Intro to Laravel PHP FrameworkBill Condo
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Vikas Chauhan
 

Viewers also liked (15)

PPT - A slice of cake php
PPT - A slice of cake phpPPT - A slice of cake php
PPT - A slice of cake php
 
Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.
 
How to learn to build your own PHP framework
How to learn to build your own PHP frameworkHow to learn to build your own PHP framework
How to learn to build your own PHP framework
 
Php Frameworks
Php FrameworksPhp Frameworks
Php Frameworks
 
Benefits of the CodeIgniter Framework
Benefits of the CodeIgniter FrameworkBenefits of the CodeIgniter Framework
Benefits of the CodeIgniter Framework
 
Introduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniterIntroduction to MVC Web Framework with CodeIgniter
Introduction to MVC Web Framework with CodeIgniter
 
Introduction Yii Framework
Introduction Yii FrameworkIntroduction Yii Framework
Introduction Yii Framework
 
Knowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP frameworkKnowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP framework
 
A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!A Good PHP Framework For Beginners Like Me!
A Good PHP Framework For Beginners Like Me!
 
PHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniterPHP Frameworks & Introduction to CodeIgniter
PHP Frameworks & Introduction to CodeIgniter
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
 
Laravel Introduction
Laravel IntroductionLaravel Introduction
Laravel Introduction
 
Laravel 5 In Depth
Laravel 5 In DepthLaravel 5 In Depth
Laravel 5 In Depth
 
Intro to Laravel PHP Framework
Intro to Laravel PHP FrameworkIntro to Laravel PHP Framework
Intro to Laravel PHP Framework
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
 

Similar to Cake Php 1.2 (Ocphp)

CakePHP Fundamentals - 1.2 @ OCPHP
CakePHP Fundamentals - 1.2 @ OCPHPCakePHP Fundamentals - 1.2 @ OCPHP
CakePHP Fundamentals - 1.2 @ OCPHPmentos
 
Ch ch-changes cake php2
Ch ch-changes cake php2Ch ch-changes cake php2
Ch ch-changes cake php2markstory
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastMichelangelo van Dam
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Michelangelo van Dam
 
Quality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormQuality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormMichelangelo van Dam
 
Apache Wicket Web Framework
Apache Wicket Web FrameworkApache Wicket Web Framework
Apache Wicket Web FrameworkLuther Baker
 
Talkaboutlithium
TalkaboutlithiumTalkaboutlithium
Talkaboutlithiumnoppoman722
 
Federico Feroldi - Scala microservices
Federico Feroldi - Scala microservicesFederico Feroldi - Scala microservices
Federico Feroldi - Scala microservicesScala Italy
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Michelangelo van Dam
 
The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)Fabien Potencier
 
Launch Arguments & NSUserDefaults by Franck Lefebvre
Launch Arguments & NSUserDefaults by Franck LefebvreLaunch Arguments & NSUserDefaults by Franck Lefebvre
Launch Arguments & NSUserDefaults by Franck LefebvreCocoaHeads France
 
Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)Pavel Novitsky
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsMike Subelsky
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Michelangelo van Dam
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207patter
 
Synapseindia reviews sharing intro cakephp
Synapseindia reviews sharing intro cakephpSynapseindia reviews sharing intro cakephp
Synapseindia reviews sharing intro cakephpSynapseindiaComplaints
 

Similar to Cake Php 1.2 (Ocphp) (20)

CakePHP Fundamentals - 1.2 @ OCPHP
CakePHP Fundamentals - 1.2 @ OCPHPCakePHP Fundamentals - 1.2 @ OCPHP
CakePHP Fundamentals - 1.2 @ OCPHP
 
Ch ch-changes cake php2
Ch ch-changes cake php2Ch ch-changes cake php2
Ch ch-changes cake php2
 
Workshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfastWorkshop quality assurance for php projects - phpbelfast
Workshop quality assurance for php projects - phpbelfast
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 
Quality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStormQuality assurance for php projects with PHPStorm
Quality assurance for php projects with PHPStorm
 
Apache Wicket Web Framework
Apache Wicket Web FrameworkApache Wicket Web Framework
Apache Wicket Web Framework
 
Talkaboutlithium
TalkaboutlithiumTalkaboutlithium
Talkaboutlithium
 
Bake by cake php2.0
Bake by cake php2.0Bake by cake php2.0
Bake by cake php2.0
 
Federico Feroldi - Scala microservices
Federico Feroldi - Scala microservicesFederico Feroldi - Scala microservices
Federico Feroldi - Scala microservices
 
CakePHP
CakePHPCakePHP
CakePHP
 
Enterprise Cake
Enterprise CakeEnterprise Cake
Enterprise Cake
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)The symfony platform: Create your very own framework (PHP Quebec 2008)
The symfony platform: Create your very own framework (PHP Quebec 2008)
 
Launch Arguments & NSUserDefaults by Franck Lefebvre
Launch Arguments & NSUserDefaults by Franck LefebvreLaunch Arguments & NSUserDefaults by Franck Lefebvre
Launch Arguments & NSUserDefaults by Franck Lefebvre
 
Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)Meet Magento Belarus debug Pavel Novitsky (eng)
Meet Magento Belarus debug Pavel Novitsky (eng)
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
symfony on action - WebTech 207
symfony on action - WebTech 207symfony on action - WebTech 207
symfony on action - WebTech 207
 
Synapseindia reviews sharing intro cakephp
Synapseindia reviews sharing intro cakephpSynapseindia reviews sharing intro cakephp
Synapseindia reviews sharing intro cakephp
 
My Development Story
My Development StoryMy Development Story
My Development Story
 

Recently uploaded

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 

Recently uploaded (20)

WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 

Cake Php 1.2 (Ocphp)

  • 1. CakePHP Bakery API Manual Forge Trac 1.2 @ OCPHP August 9, 2007 © 2007 Cake Software Foundation
  • 2. CakePHP Bakery API Manual Forge Trac Why CakePHP? MVC architecture Convention over Configuration Flexible and Extensible Write less, do more Open Source, Large Community MIT License © 2007 Cake Software Foundation
  • 3. CakePHP Bakery API Manual Forge Trac CakePHP the right way by: Amy Hoy, http://slash7.com/ Think twice, code once Loose couple © 2007 Cake Software Foundation
  • 4. CakePHP Bakery API Manual Forge Trac Hot out of the oven Behaviors Router “With” Associations Email Enhanced Validation Security Forms Authentication Pagination Configure i18n + l10n Cache Engines Acl Console © 2007 Cake Software Foundation
  • 5. CakePHP Bakery API Manual Forge Trac Behaviors extend models encapsulate reusable functionality use callbacks for automagic © 2007 Cake Software Foundation
  • 6. CakePHP Bakery API Manual Forge Trac <?php class CoolBehavior extends ModelBehavior { var $settings = array(); function setup(&$model, $config = array()) { $this->settings = $config; } /* Callbacks */ function beforeFind(&$model, $query) { } function afterFind(&$model, $results, $primary) { } function beforeSave(&$model) { } function afterSave(&$model, $created) { } function beforeDelete(&$model) { } function afterDelete(&$model) { } function onError(&$model, $error) { } /* Custom Methods */ function myCustomMethod(&$model, $data = array()) { return array_merge($model->data, $data); } } ?> © 2007 Cake Software Foundation
  • 7. CakePHP Bakery API Manual Forge Trac <?php class Post extends AppModel { var $actsAs = array(‘Cool’=>array(‘field’=>’cool_id’)); function doSomething($cool = null) { $this->myCustomMethod(array(‘cool_id’=> $cool)); } } ?> <?php class PostsController extends AppController { var $name = ‘Posts’; function index() { $this->set(‘posts’, $this->Post->doSomething(5)); } } ?> © 2007 Cake Software Foundation
  • 8. CakePHP Bakery API Manual Forge Trac “With” Associations enables extra fields in join tables access to model for join table tags posts posts_tag id id s key id title name post_id body created tag_id created modified modified date © 2007 Cake Software Foundation
  • 9. CakePHP Bakery API Manual Forge Trac Adding “With” <?php class Post extends AppModel { var $hasAndBelongsToMany = array( ‘Tag’ => array( ‘className’ => ’Tag’, ‘with’ => ‘TaggedPost’, ) ); function beforeSave() { if(!empty($this->data[‘Tag’])) { $this->TaggedPost->save($this->data[‘Tag’]); } } } ?> © 2007 Cake Software Foundation
  • 10. CakePHP Bakery API Manual Forge Trac Using “With” <?php class PostsController extends AppController { var $name = ‘Posts’; function tags() { $this->set(‘tags’, $this->Post->TaggedPost->findAll()); } } ?> <?php foreach ($tags as $tag) : echo $tag[‘Post’][‘title’]; echo $tag[‘Tag’][‘name’]; echo $tag[‘TaggedPost’][‘date’]; endforeach; ?> © 2007 Cake Software Foundation
  • 11. CakePHP Bakery API Manual Forge Trac Validation is King alphaNumeric email number between equalTo numeric blank file phone cc ip postal comparison maxLength ssn custom minLength url date money userDefined decimal multiple © 2007 Cake Software Foundation
  • 12. CakePHP Bakery API Manual Forge Trac Using Validation <?php class Post extends AppModel { var $validate = array( 'title' => array( 'required' => VALID_NOT_EMPTY, 'length' => array( 'rule' => array('maxLength', 100)) ), 'body' => VALID_NOT_EMPTY ); } ?> © 2007 Cake Software Foundation
  • 13. CakePHP Bakery API Manual Forge Trac Forms made simple <?php  echo $form->create('Post');     echo $form->input('title', array('error' => array(          'required' => 'Please specify a valid title',          'length' => 'The title must have no more than 100 characters'      ) ) );  echo $form->input('body', array('error' => 'Please specify a valid body')); echo $form->end('Add'); ?> © 2007 Cake Software Foundation
  • 14. CakePHP Bakery API Manual Forge Trac More about Forms <?php  /* Change the action */ echo $form->create('User', array(‘action’=> ‘login’)); ?> <?php  /* Change the type for uploading files */ echo $form->create('Image', array(‘type’=> ‘file’)); echo $form->input('file', array(‘type’=> ‘file’)); echo $form->end(‘Upload’); ?> <?php  /* the three line form */ echo $form->create('Post'); echo $form->inputs(‘Add a Post’); echo $form->end(‘Add’); ?> © 2007 Cake Software Foundation
  • 15. CakePHP Bakery API Manual Forge Trac Pagination <?php class PostsController extends AppController { var $name = ‘Posts’; var $paginate = array(‘order’=> ‘Post.created DESC’); function index() { $this->set(‘posts’, $this->paginate()); } } ?> <?php echo $paginator->counter(array( 'format' => 'Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%' )); echo $paginator->prev('<< previous', array(), null, array('class'=>'disabled')); echo $paginator->numbers(); echo $paginator->sort(‘Created’); echo $paginator->next('next >>', array(), null, array('class'=>'disabled')); © 2007 Cake Software Foundation
  • 16. CakePHP Bakery API Manual Forge Trac i18n/L10n built in gettext for static strings TranslationBehavior for dynamic data console extractor © 2007 Cake Software Foundation
  • 17. CakePHP Bakery API Manual Forge Trac gettext style <?php /* echo a string */ __(‘Translate me’); /* return a string */ $html->link(__(‘Translate me’, true), array(‘controller’=>’users’)); /* by category : LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES and LC_ALL.*/ __c(‘Translate me’, ‘LC_CTYPE’); /* get plurals by number*/ __n(‘Translate’, ‘Translates’, 2); /* override the domain.*/ __d(‘posts’, ‘Translate me’); /* override the domain by category.*/ __dc(‘posts’, ‘Translate me’, ‘LC_CTYPE’); © 2007 Cake Software Foundation
  • 18. CakePHP Bakery API Manual Forge Trac Translation Behavior <?php class Post extends AppModel { var $actsAs = array(‘Translation’=> array(‘title’, ‘body’)); } ?> CREATE TABLE i18n_content ( CREATE TABLE i18n ( id int(10) NOT NULL auto_increment, id int(10) NOT NULL auto_increment, content text, locale varchar(6) NOT NULL, PRIMARY KEY (id) i18n_content_id int(10) NOT NULL, ); model varchar(255) NOT NULL, row_id int(10) NOT NULL, field varchar(255) NOT NULL, PRIMARY KEY (id), KEY locale (locale), KEY i18n_content_id (i18n_content_id), KEY row_id (row_id), KEY model (model), KEY field (field) ); © 2007 Cake Software Foundation
  • 19. CakePHP Bakery API Manual Forge Trac Acl abstracted for maximum compatibility component for controller behavior for model © 2007 Cake Software Foundation
  • 20. CakePHP Bakery API Manual Forge Trac Acl behavior <?php <?php class User extends AppModel { class Post extends AppModel { var $actsAs = array(‘Acl’=> ‘requester’); var $actsAs = array(‘Acl’=> ‘controlled’); function parentNode() {} function parentNode() {} function bindNode($object) { function bindNode($object) {} if (!empty($object['User']['role'])) { } return 'Roles/' . $object['User']['role']; ?> } } function roles() { return $this->Aro->findAll(); } } ?> © 2007 Cake Software Foundation
  • 21. CakePHP Bakery API Manual Forge Trac Routing reverse routes magic variables named parameters parseExtensions REST resource mapping © 2007 Cake Software Foundation
  • 22. CakePHP Bakery API Manual Forge Trac Reversing Routes <?php Route::connect(‘/’, array(‘controller’=>’pages’, ‘action’=>’display’, ‘home’)); ?> <?php echo $html->link(‘Go Home’, array(‘controller’=> ‘pages’, ‘action’=> ‘display’, home)); ?> © 2007 Cake Software Foundation
  • 23. CakePHP Bakery API Manual Forge Trac Magic Variables $Action => Matches most common action names $Year => Matches any year from 1000 to 2999 $Month => Matches any valid month with a leading zero (01 - 12) $Day => Matches any valid day with a leading zero (01 - 31) $ID => Matches any valid whole number (0 - 99999.....) Router::connect( '/:controller/:year/:month/:day', array('action' => 'index', 'day' => null), array('year' => $Year, 'month' => $Month, 'day' => $Day) ); Router::connect( '/:controller/:id', array('action' => 'index', ‘id’=> ‘1’), array('id' => $ID) ); © 2007 Cake Software Foundation
  • 24. CakePHP Bakery API Manual Forge Trac Named Args http://cakephp.org/posts/index/page:2/sort:title <?php class PostsController extends AppController { var $name = ‘Posts’; function index() { $this->passedArgs[‘page’]; $this->passedArgs[‘sort’]; } } ?> © 2007 Cake Software Foundation
  • 25. CakePHP Bakery API Manual Forge Trac Parsing Extensions /* get everything */ Router::parseExtensions(); /* more fine grained */ Router::parseExtensions(‘xml’, ‘html’); maps views to unique locations http://cakephp.org/posts/index.rss Router::parseExtensions(‘rss’); <?php //app/views/posts/rss/index.ctp echo $rss->items($posts, 'transformRSS'); function transformRSS($post) { return array( 'title' => $post['Post']['title'], 'link' => array('url'=>'/posts/view/'.$post['Post]['id']), 'description' => substr($post['Post']['body'], 0, 200), 'pubDate' => date('r', strtotime($post['Post']['created'])), ); } ?> © 2007 Cake Software Foundation
  • 26. CakePHP Bakery API Manual Forge Trac Email $this->Email->to = $user['User']['email']; $this->Email->from = Configure::read('Site.email'); $this->Email->subject = Configure::read('Site.name').' Password Reset URL'; $content[] = 'A request to reset you password has been submitted to '.Configure::read('Site.name'); $content[] = 'Please visit the following url to have your temporary password sent'; $content[] = Router::url('/users/verify/reset/'.$token, true); if($this->Email->send($content)) { $this->Session->setFlash('You should receive an email with further instruction shortly'); $this->redirect('/', null, true); } /* Sending HTML and Text */ $this->Email->sendAs = ‘both’; $this->Email->template = ‘reset_password’; /* HTML templates */ //app/views/elements/email/html/reset_password.ctp /* TEXT templates */ //app/views/elements/email/text © 2007 Cake Software Foundation
  • 27. CakePHP Bakery API Manual Forge Trac Security HTTP Auth <?php class PostsController extends AppController { var $name = ‘Posts’; var $components = array(‘Security’); function beforeFilter() { $this->Security->requireLogin(‘add’, ‘edit’, ‘delete’); $this->Security->loginUsers = array('cake'=>'tooeasy'); } } ?> © 2007 Cake Software Foundation
  • 28. CakePHP Bakery API Manual Forge Trac Authentication <?php class PostsController extends AppController { var $name = ‘Posts’; var $components = array(‘Auth’); } ?> authenticate any model: User, Member, Editor, Contact authorize against models, controllers, or abstract objects automate login © 2007 Cake Software Foundation
  • 29. CakePHP Bakery API Manual Forge Trac Auth setup <?php class PostsController extends AppController { var $name = ‘Posts’; var $components = array(‘Auth’); function beforeFilter() { $this->Auth->userModel = 'Member'; $this->Auth->loginAction = '/members/login'; $this->Auth->loginRedirect = '/members/index'; $this->Auth->fields = array('username' => 'username', 'password' => 'pword'); $this->Auth->authorize = array('model'=>'Member'); $this->Auth->mapActions(array( 'read' => array('display'), 'update' => array('admin_show', 'admin_hide'), )); } } ?> © 2007 Cake Software Foundation
  • 30. CakePHP Bakery API Manual Forge Trac Authorize a Model <?php class Member extends Model { var $name = 'Member'; function isAuthorized($user, $controller, $action) { switch ($action) { case 'default': return false; break; case 'delete': if($user[['Member']['role'] == 'admin') { return true; } break; } } } ?> © 2007 Cake Software Foundation
  • 31. CakePHP Bakery API Manual Forge Trac Authorize a Controller <?php class PostsController extends AppController { var $name = ‘Posts’; var $components = array(‘Auth’); function beforeFilter() { $this->Auth->authorize = ‘controller’; } function isAuthorized() { if($this->Auth->user('role') == 'admin') { return true; } } } ?> © 2007 Cake Software Foundation
  • 32. CakePHP Bakery API Manual Forge Trac Authorize CRUD <?php class PostsController extends AppController { var $name = ‘Posts’; var $components = array(‘Auth’); function beforeFilter() { $this->Auth->authorize = ‘crud’; $this->Auth->actionPath = 'Root/'; } } ?> $this->Acl->allow('Roles/Admin', 'Root'); $this->Acl->allow('Roles/Admin', 'Root/Posts'); © 2007 Cake Software Foundation
  • 33. CakePHP Bakery API Manual Forge Trac Configure <?php Configure::write(‘Oc.location’, ‘Buddy Group’); Configure::write(‘Oc’, array(‘location’=>‘Buddy Group’)); Configure::read(‘Oc.location’); Configure::store('Groups', 'groups', array('Oc' => array(‘location’=>’Buddy Group’))); Configure::load('groups'); ?> © 2007 Cake Software Foundation
  • 34. CakePHP Bakery API Manual Forge Trac Cache Engines File xcache APC Model Memcache Cache::engine(‘File’, [settings]); $data = Cache::read(‘post’); if(empty($data)) { $data = $this->Post->findAll(); Cache::write(‘post’, $data); } © 2007 Cake Software Foundation
  • 35. CakePHP Bakery API Manual Forge Trac Console Makes writing Command Line Interfaces (CLI) cake Shells Tasks Access to models © 2007 Cake Software Foundation
  • 36. CakePHP Bakery API Manual Forge Trac Core Shells Acl Extractor Bake Console API © 2007 Cake Software Foundation
  • 37. CakePHP Bakery API Manual Forge Trac The Bake Shell Tasks Model - cake bake model Post Controller - cake bake controller Posts View - cake bake view Posts DbConfig - cake bake db_config Project - cake bake project Custom view templates, oh yeah! © 2007 Cake Software Foundation
  • 38. CakePHP Bakery API Manual Forge Trac Your Own Shell <?php class DemoShell extends Shell { var $uses = array('Post'); var $tasks = array('Whatever', 'Another'); function initialize() {} function startup() {} function main() { $this->out('Demo Script'); } function something() { $this->Whatver->execute(); } function somethingElse() { $posts = $this->Post->findAll(); foreach($posts as $post) { $this->out(‘title : ‘ . $post[‘Post’][‘title’]); } } } ?> © 2007 Cake Software Foundation
  • 39. CakePHP Bakery API Manual Forge Trac More.... Xml reading and writing HttpSockets Themes Cookies ...... © 2007 Cake Software Foundation
  • 40. CakePHP Bakery API Manual Forge Trac Questions? © 2007 Cake Software Foundation