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
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
Ok. But why CakePHP? MVC architecture Convention over Configuration Automatic code generation (aka bake) Associations Support for components/helpers/behaviors Supports callback methods
continued... Supports theming and Internationalization Callback methods Routing Gentle learning curve and much more ...
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
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
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
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
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
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 ...
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
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
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.
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
References http://cakephp.org http://book.cakephp.org http://bakery.cakephp.org http://cakeforge.org http://www.sanisoft.com/blog
Thank you

Introduction to Cakephp

  • 1.
    Introduction to CakePHPBy Aditya Mooley SANIsoft Technologies Pvt. Ltd.
  • 2.
    Me Technical Managerwith SANIsoft Working with CakePHP since it started in 2005 Have one of the largest team working on CakePHP Twitter - @adityamooley
  • 3.
    Cake! PHP! Frameworkwritten 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
  • 4.
    Ok. But whyCakePHP? MVC architecture Convention over Configuration Automatic code generation (aka bake) Associations Support for components/helpers/behaviors Supports callback methods
  • 5.
    continued... Supports themingand Internationalization Callback methods Routing Gentle learning curve and much more ...
  • 6.
    Cake Community Cakebook - 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
  • 7.
    Convention over ConfigurationFollow the guidelines to name your - Model, controller, view files and classes Class methods Database tables, column names Automagic Uniform system development
  • 8.
    Convention over ConfigurationUnderscored 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
  • 9.
    Associations Ability tolink 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
  • 10.
    Components Built-in functionalityfor 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
  • 11.
    Helpers Helper classesfor 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 ...
  • 12.
    Behaviors Adds morefunctionality 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
  • 13.
    DataSources Link betweena 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
  • 14.
    Callback methods Methodscalled 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.
  • 15.
    Bake Cake bashscript Needs PHP CLI Automatic code generation using database schema Model with validations Controller with CRUD actions Necessary views for user interaction
  • 16.
    References http://cakephp.org http://book.cakephp.orghttp://bakery.cakephp.org http://cakeforge.org http://www.sanisoft.com/blog
  • 17.