Introduction to CakePHP By Aditya Mooley SANIsoft Technologies Pvt by sofiaie

VIEWS: 19 PAGES: 17

									Introduction to CakePHP




               By
         Aditya Mooley
 SANIsoft Technologies Pvt. Ltd.
                                      Me
             Technical Manager with SANIsoft
             Working with CakePHP since it started in 2005
             Have one of the largest team working on
              CakePHP
             Twitter - @adityamooley




Jan 9, 2010                 SANIsoft Technologies Pvt. Ltd.   2
                           Cake! PHP!
             Framework written in PHP for PHP
             Created by Larry E Masters (aka PhpNut)
             Follows MVC
             Current stable version (1.2.5) runs on PHP 4 and
              5
             Active community
             Work already started on versions 1.3, 2 and 3


Jan 9, 2010                  SANIsoft Technologies Pvt. Ltd.     3
                 Ok. But why CakePHP?
             MVC architecture
             Convention over Configuration
             Automatic code generation (aka bake)
             Associations
             Support for components/helpers/behaviors
             Supports callback methods



Jan 9, 2010                  SANIsoft Technologies Pvt. Ltd.   4
                          continued...
             Supports theming and Internationalization
             Callback methods
             Routing
             Gentle learning curve
             and much more ...




Jan 9, 2010                  SANIsoft Technologies Pvt. Ltd.   5
                      Cake Community
             Cake book - http://book.cakephp.org
                  Cake handbook with user comments
             Bakery - http://bakery.cakephp.org/
                  Communtity contribution to improve development
                   with CakePHP
             CakeForge - http://www.cakeforge.org/
                  Hosting opensource projects built with CakePHP
             IRC channel - #cakephp @ irc.freenode.net


Jan 9, 2010                  SANIsoft Technologies Pvt. Ltd.        6
               Convention over Configuration

             Follow the guidelines to name your -
                  Model, controller, view files and classes
                  Class methods
                  Database tables, column names
             Automagic
             Uniform system development




Jan 9, 2010                   SANIsoft Technologies Pvt. Ltd.   7
                Convention over Configuration

             Underscored filename and CamelCase class name
             UserDetailsController -> user_details_controller.php
             Singular Model
             Plural Controller
             Plural database table name
             Person Model, People Controller and people DB table
             Primary key name - id



Jan 9, 2010                       SANIsoft Technologies Pvt. Ltd.    8
                           Associations
             Ability to link models through relational mapping
             HasOne
                 User hasOne Profile
             HasMany
                  User hasMany Posts
             BelongsTo
                 Post belongsTo User
             HasAndBelongsToMany (HABTM)
                  Post has and belong to many Tags
Jan 9, 2010                    SANIsoft Technologies Pvt. Ltd.    9
                            Components
             Built-in functionality for several commonly used tasks
             Enhances controller functionality
             Auth – User authentication system
             Acl – Access control list
             Email – Send mail using PHP's mail function and smtp
             Security – Get rid of CSRF and form tampering
             Possibility to write custom components



Jan 9, 2010                     SANIsoft Technologies Pvt. Ltd.        10
                               Helpers
             Helper classes for views.
             Paginator – Handles pagination and sorting
             Form – Easier creation of form elements
             HTML – Creates uniform and XHTML tags
             RSS – Makes generation of RSS feeds easy
             many more ...



Jan 9, 2010                   SANIsoft Technologies Pvt. Ltd.   11
                           Behaviors
             Adds more functionality to models without
              cluttering the model class
             Can be shared by multiple models
             Can be attached to model using $actsAs or even
              on the fly
             Examples – upload, slug, tags




Jan 9, 2010                  SANIsoft Technologies Pvt. Ltd.   12
                          DataSources
             Link between a model and its source of data
             Mostly a database like MySQL, PostgreSQL, etc.
             Possibility to connect to unconventional sources
              of data like Salesforce and other REST APIs
             More examples: Twitter, Paypal, etc




Jan 9, 2010                  SANIsoft Technologies Pvt. Ltd.     13
                      Callback methods
             Methods called from within the framework
              before/after a specific action.
             Used to execute special logic before Cake's
              default operation.
             Controller callbacks
                  beforeFilter, afterFilter, beforeRender
             Model callbacks
                  BeforeFind, afterFind, beforeValidate, beforeSave,
                   afterSave, etc.

Jan 9, 2010                   SANIsoft Technologies Pvt. Ltd.      14
                                   Bake
             Cake bash script
             Needs PHP CLI
             Automatic code generation using database
              schema
             Model with validations
             Controller with CRUD actions
             Necessary views for user interaction


Jan 9, 2010                  SANIsoft Technologies Pvt. Ltd.   15
                           References
             http://cakephp.org
             http://book.cakephp.org
             http://bakery.cakephp.org
             http://cakeforge.org
             http://www.sanisoft.com/blog




Jan 9, 2010                  SANIsoft Technologies Pvt. Ltd.   16
                Thank you




Jan 9, 2010   SANIsoft Technologies Pvt. Ltd.   17

								
To top