Suche senden
Hochladen
Cakephp
•
10 gefällt mir
•
6,328 views
Khalid Alharbi
Folgen
CakePHP: The Rapid Development PHP Framework.
Weniger lesen
Mehr lesen
Technologie
Melden
Teilen
Melden
Teilen
1 von 48
Jetzt herunterladen
Downloaden Sie, um offline zu lesen
Empfohlen
CakePHP
CakePHP
Walther Lalk
PPT - A slice of cake php
PPT - A slice of cake php
Konstant Infosolutions Pvt. Ltd.
CakePHP 2.0 - It'll rock your world
CakePHP 2.0 - It'll rock your world
Graham Weldon
Learn How To Develop With CakePHP
Learn How To Develop With CakePHP
Michael Bourque
9 Awesome cake php tutorials and resources
9 Awesome cake php tutorials and resources
iScripts
Introduction to CakePHP
Introduction to CakePHP
mohamedsamirgalal
Top 50 Interview Questions and Answers in CakePHP
Top 50 Interview Questions and Answers in CakePHP
Ketan Patel
Cakephp manual-11
Cakephp manual-11
Aditya Pandey
Empfohlen
CakePHP
CakePHP
Walther Lalk
PPT - A slice of cake php
PPT - A slice of cake php
Konstant Infosolutions Pvt. Ltd.
CakePHP 2.0 - It'll rock your world
CakePHP 2.0 - It'll rock your world
Graham Weldon
Learn How To Develop With CakePHP
Learn How To Develop With CakePHP
Michael Bourque
9 Awesome cake php tutorials and resources
9 Awesome cake php tutorials and resources
iScripts
Introduction to CakePHP
Introduction to CakePHP
mohamedsamirgalal
Top 50 Interview Questions and Answers in CakePHP
Top 50 Interview Questions and Answers in CakePHP
Ketan Patel
Cakephp manual-11
Cakephp manual-11
Aditya Pandey
CakePHP - Admin Acl Controlled
CakePHP - Admin Acl Controlled
Luís Fred
CakePHP and AJAX
CakePHP and AJAX
Mark Scherer
2 introduction-php-mvc-cakephp-m2-installation-slides
2 introduction-php-mvc-cakephp-m2-installation-slides
MasterCode.vn
CakePHP: An Introduction
CakePHP: An Introduction
Diana Jayne Gonzales
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
Joshua Warren
Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)
Katy Slemon
PHPUnit with CakePHP and Yii
PHPUnit with CakePHP and Yii
madhavi Ghadge
Behaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & Drupal
sparkfabrik
Getting started-with-zend-framework
Getting started-with-zend-framework
Marcelo da Rocha
Presentation laravel 5 4
Presentation laravel 5 4
Christen Gjølbye Christensen
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Jackson F. de A. Mafra
Php Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant Killer
Jackson F. de A. Mafra
Plugin architecture (Extensible Application Architecture)
Plugin architecture (Extensible Application Architecture)
Chinmoy Mohanty
Why Laravel?
Why Laravel?
Jonathan Goode
Developing html5 mobile applications using cold fusion 11
Developing html5 mobile applications using cold fusion 11
ColdFusionConference
Advanced PHP Web Development Tools in 2015
Advanced PHP Web Development Tools in 2015
iScripts
Introduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC Frameworks
Gerald Krishnan
PloneNG: What's new in Plone 4.2, 4.3, and beyond
PloneNG: What's new in Plone 4.2, 4.3, and beyond
David Glick
Phalcon - Giant Killer
Phalcon - Giant Killer
Jackson F. de A. Mafra
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
Viral Solani
Php Framework
Php Framework
cncwebworld
Php framework
Php framework
cncwebworld
Weitere ähnliche Inhalte
Was ist angesagt?
CakePHP - Admin Acl Controlled
CakePHP - Admin Acl Controlled
Luís Fred
CakePHP and AJAX
CakePHP and AJAX
Mark Scherer
2 introduction-php-mvc-cakephp-m2-installation-slides
2 introduction-php-mvc-cakephp-m2-installation-slides
MasterCode.vn
CakePHP: An Introduction
CakePHP: An Introduction
Diana Jayne Gonzales
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
Joshua Warren
Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)
Katy Slemon
PHPUnit with CakePHP and Yii
PHPUnit with CakePHP and Yii
madhavi Ghadge
Behaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & Drupal
sparkfabrik
Getting started-with-zend-framework
Getting started-with-zend-framework
Marcelo da Rocha
Presentation laravel 5 4
Presentation laravel 5 4
Christen Gjølbye Christensen
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Jackson F. de A. Mafra
Php Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant Killer
Jackson F. de A. Mafra
Plugin architecture (Extensible Application Architecture)
Plugin architecture (Extensible Application Architecture)
Chinmoy Mohanty
Why Laravel?
Why Laravel?
Jonathan Goode
Developing html5 mobile applications using cold fusion 11
Developing html5 mobile applications using cold fusion 11
ColdFusionConference
Advanced PHP Web Development Tools in 2015
Advanced PHP Web Development Tools in 2015
iScripts
Introduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC Frameworks
Gerald Krishnan
PloneNG: What's new in Plone 4.2, 4.3, and beyond
PloneNG: What's new in Plone 4.2, 4.3, and beyond
David Glick
Phalcon - Giant Killer
Phalcon - Giant Killer
Jackson F. de A. Mafra
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
Viral Solani
Was ist angesagt?
(20)
CakePHP - Admin Acl Controlled
CakePHP - Admin Acl Controlled
CakePHP and AJAX
CakePHP and AJAX
2 introduction-php-mvc-cakephp-m2-installation-slides
2 introduction-php-mvc-cakephp-m2-installation-slides
CakePHP: An Introduction
CakePHP: An Introduction
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
Go swagger tutorial how to create golang api documentation using go swagger (1)
Go swagger tutorial how to create golang api documentation using go swagger (1)
PHPUnit with CakePHP and Yii
PHPUnit with CakePHP and Yii
Behaviour Driven Development con Behat & Drupal
Behaviour Driven Development con Behat & Drupal
Getting started-with-zend-framework
Getting started-with-zend-framework
Presentation laravel 5 4
Presentation laravel 5 4
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Phalcon 2 High Performance APIs - DevWeekPOA 2015
Php Conference Brazil - Phalcon Giant Killer
Php Conference Brazil - Phalcon Giant Killer
Plugin architecture (Extensible Application Architecture)
Plugin architecture (Extensible Application Architecture)
Why Laravel?
Why Laravel?
Developing html5 mobile applications using cold fusion 11
Developing html5 mobile applications using cold fusion 11
Advanced PHP Web Development Tools in 2015
Advanced PHP Web Development Tools in 2015
Introduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC Frameworks
PloneNG: What's new in Plone 4.2, 4.3, and beyond
PloneNG: What's new in Plone 4.2, 4.3, and beyond
Phalcon - Giant Killer
Phalcon - Giant Killer
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
Ähnlich wie Cakephp
Php Framework
Php Framework
cncwebworld
Php framework
Php framework
cncwebworld
Why CakePHP Is Superior to Other Web Frameworks! Examine Its Pros & Cons For ...
Why CakePHP Is Superior to Other Web Frameworks! Examine Its Pros & Cons For ...
JPLoft Solutions
Know about cake php framework with vertexplus
Know about cake php framework with vertexplus
VertexPlus Softwares Pvt. Ltd.
Benefits of cake_php_in_web_development
Benefits of cake_php_in_web_development
Xicom Technologies
Trusted PHP Development Services in the USA
Trusted PHP Development Services in the USA
technoprofiles
cakephp UDUYKTHA (1)
cakephp UDUYKTHA (1)
Varsha Krishna
Rapid Development With CakePHP
Rapid Development With CakePHP
Edureka!
Building Restful Web App Rapidly in CakePHP
Building Restful Web App Rapidly in CakePHP
Edureka!
Web application development with laravel php framework version 4
Web application development with laravel php framework version 4
Untung D Saptoto
Cakephp
Cakephp
Ly Channa
Cakephp
Cakephp
Ly Channa
Cakephp
Cakephp
Ly Channa
Laravel overview
Laravel overview
Obinna Akunne
PHP Frameworks
PHP Frameworks
Dumindu Pahalawatta
PHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniter
KHALID C
Laravel : A Fastest Growing Kid
Laravel : A Fastest Growing Kid
Endive Software
Apigility-powered API's on IBM i
Apigility-powered API's on IBM i
chukShirley
Principles of MVC for Rails Developers
Principles of MVC for Rails Developers
Edureka!
yii framework
yii framework
Akhil Kumar
Ähnlich wie Cakephp
(20)
Php Framework
Php Framework
Php framework
Php framework
Why CakePHP Is Superior to Other Web Frameworks! Examine Its Pros & Cons For ...
Why CakePHP Is Superior to Other Web Frameworks! Examine Its Pros & Cons For ...
Know about cake php framework with vertexplus
Know about cake php framework with vertexplus
Benefits of cake_php_in_web_development
Benefits of cake_php_in_web_development
Trusted PHP Development Services in the USA
Trusted PHP Development Services in the USA
cakephp UDUYKTHA (1)
cakephp UDUYKTHA (1)
Rapid Development With CakePHP
Rapid Development With CakePHP
Building Restful Web App Rapidly in CakePHP
Building Restful Web App Rapidly in CakePHP
Web application development with laravel php framework version 4
Web application development with laravel php framework version 4
Cakephp
Cakephp
Cakephp
Cakephp
Cakephp
Cakephp
Laravel overview
Laravel overview
PHP Frameworks
PHP Frameworks
PHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniter
Laravel : A Fastest Growing Kid
Laravel : A Fastest Growing Kid
Apigility-powered API's on IBM i
Apigility-powered API's on IBM i
Principles of MVC for Rails Developers
Principles of MVC for Rails Developers
yii framework
yii framework
Kürzlich hochgeladen
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
The Digital Insurer
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
UK Journal
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
Enterprise Knowledge
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
DianaGray10
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
Remote DBA Services
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Miguel Araújo
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
Maria Levchenko
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
lior mazor
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
Product Anonymous
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
The Digital Insurer
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
sudhanshuwaghmare1
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
The Digital Insurer
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
Radu Cotescu
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
ThousandEyes
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
hans926745
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
sammart93
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
Igalia
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Gabriella Davis
Kürzlich hochgeladen
(20)
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
Cakephp
1.
CakePHP
The Rapid Development PHP Framework By Khalid Alharbi Khalid Alharbi, © 2011 1
2.
Contents
What’s CakePHP? History. Features. MVC in CakePHP. Naming Convention. Core concepts. Installing and running Cake. Khalid Alharbi, © 2011 2
3.
Contents Cont.
Simple Cake Application. Database Cake Application. Bake Script. Layouts. Routes. Extending MVC Structure. Advanced Cake techniques. Cake Community. Khalid Alharbi, © 2011 3
4.
What is CakePHP
? According to the official CakePHP website, cakephp.org, “CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications. Using commonly known design patterns like MVC and ORM within the convention over configuration paradigm, CakePHP reduces development costs and helps developers write less code” Khalid Alharbi, © 2011 4
5.
History
CakePHP was created by Michal Tatarynowicz On April 15, 2005. Inspired by Roby on Rails. Michal published it under MIT licence and opened it to the community developers. In July 2005, Larry E Masters (aka PhpNut) took over as the lead developer. In December 2005, Larry and Garrett J. Woodworth (aka gwoo) founded the Cake Software Foundation to promote development related to CakePHP. Khalid Alharbi, © 2011
6.
Features
It’s PHP! Compatibles with versions 4 and 5. Open Source, MIT license. Object Oriented. Design Patterns: MVC and ORM. Convention over configuration. Framework not set of libraries. Bake Script: Automates CRUD scripting. Khalid Alharbi, © 2011 6
7.
Features Cont.
Scaffolding: single line view rendering. Helpers: standard HTML, Ajax, and JavaScript helpers to create views. Customizable Elements: add elements as plugins into the application. Input validation and data sanitization tools to help create secure application. Search engine friendly URLs. Large growing active community. Extremely simple – It’s a piece of Cake! Khalid Alharbi, © 2011 7
8.
MVC Pattern
Cake enforces Model View Controller (MVC) Pattern. Cake splits operations into three parts: Models: used for all database interactions. Views: used for all output and displays. Controllers: used to control the application flow. Khalid Alharbi, © 2011
9.
How Does MVC
Work? (I) No MVC PHP App CakePHP MVC App Maintenance headache! Doesn’t scale well because everything is in the script. Khalid Alharbi, © 2011
10.
How Does MVC
Work? (II) ① The client sends request. According to the CakePHP convention, the URL looks like: http://{Domain} /{Application}/{Controller}/{Action}/{Parameter 1, etc.} ② The dispatcher script parses the URL, determines which controller to execute, and forwards the request to the Controller. ③ The action (method) in the controller needs to access data, so it sends a database request to the Model. ④ The model executes the database request, pulls the output, ⑤ The Model sends the output to the Controller. ⑥ The Controller sends the output to the corresponding view. ⑦ The View adds any design element to the output and sends it to the client’s browser. Khalid Alharbi, © 2011 10
11.
Why CakePHP MVC
? Reduce redundancy. Organize the different tasks of the web app. No need for include statements in PHP scripts. Follow Agile techniques. Easy to debug and maintain. Khalid Alharbi, © 2011 11
12.
Cake Naming Convention
(I) Cake adheres the idea of “convention over configuration.” This organizes the operations of the web application. It’s strongly recommended to follow Cake's naming convention. More than one word in the name, must be separated by _ when naming the file and camel cases when naming the class. Khalid Alharbi, © 2011 12
13.
Cake Naming Convention
(II) DB Table : Plural form in lowercase letters. ex: orders. The MVC parts must be named as the following: File Name Class Name Base Class Location Name Model Singular form of the The file name in a AppModel /app/models table name with .php Camel case. ex: extension ex: order.php Order Controller tablename_controller The table name AppController /app/controllers with .php extension. ex: appended orders_controller.php Controller. ex: OrdersController View The action name in the No classes; a view contains only /app/views/ controller with .ctp html tags and php scripts. controllerName extension. ex: add.ctp Khalid Alharbi, © 2011 13
14.
Core Concepts
Models and Associations. Controllers. Views. Khalid Alharbi, © 2011 14
15.
Models and Association
(I) The model is the access point to a table in the DB. The model can contain data validation rules and association information. Cake offers Object Relational Mapping (ORM) to handle database relationships. Using Cake’s ORM, CRUD operations are done without writing complex SQL queries. Relationships between tables are defined through association. Khalid Alharbi, © 2011 15
16.
Models and Association
(II) Association helps cake link between models through relational mapping. Association types: hasOne: one-to-one relationship. ex: user “has one” account. hasMany: a user “has many” posts. belongsTo: a post “belongs to” one user. hasAndBelongsToMany: a post “has and belongs to many” tags. Khalid Alharbi, © 2011 16
17.
Controllers
Controllers handle all logic and requests. Use functions like set(), and render() to call out the views and provide it with variables. Use read(), and find() model’s methods to get a list of fields from the database. Use the standardized array $this->data to handle user form data in the view and runs it through the Model. Khalid Alharbi, © 2011 17
18.
Views (I)
Views handle the presentation layer and displays. Views contain HTML and PHP scripts. Views are associated with actions in the controller. When Cake launches an action in the controller, it will automatically render the corresponding view for it or display error. If the action in the controller is only called by another action, then there is no need to create a view for it. Khalid Alharbi, © 2011 18
19.
Views (II)
When a user fills out a form, Cake places the form data into the $this->data standard array. Cake parses the $this->data like the following: User-submitted data can be pulled from $this->data array like any PHP array. Ex: $this->data['Post']['date']['year’] Khalid Alharbi, © 2011 19
20.
Installing CakePHP (I)
Before beginning, install these on your localhost: Apache server with mod_rewrite. PHP 4.3.2 or greater. MySQL (the default database engine in Cake) or you can use any supported DBMSs: PostgreSQL, Microsoft SQL Server 2000, Firebird, IBM DB2,Oracle, SQLite, ODBC, or ADOdb. You can easily install all of these with XAMPP! Download the latest stable release version 1.3.8 of Cake from http://cakephp.org. Extract the compressed package to your local host root. Khalid Alharbi, © 2011 20
21.
Installing CakePHP (II)
You will end up with the following directories: /app contains all controllers, models, views, and anything related to your application. /cake contains the cake’s libraries and scripts. /plugins contains plugins packages. /vendors contains other independent Cake scripts. Khalid Alharbi, © 2011 21
22.
Running CakePHP
Before running: Change the /tmp folder permission to read and write. Change the security.salt value in app/config/core.php Create the database. Rename app/config/database.php.default to database.php and edit the connection settings. Go to http://localhost/cakephp Khalid Alharbi, © 2011 22
23.
The Resulting Application Khalid
Alharbi, © 2011 23
24.
The oven is
ready! Let’s put on the cooking hat and bake our first cake ☺ Khalid Alharbi, © 2011 24
25.
Hello World! (I)
The required steps: Create the Model: /app/models/example.php Create the controller: /app/controllers/ examples_controller.php Khalid Alharbi, © 2011 25
26.
Hello World! (II)
Create the view: /app/views/examples/index.ctp Running the app: navigate to http://localhost/ application_name/examples/index Khalid Alharbi, © 2011 26
27.
Blog Application (I)
Creating a blog using CakePHP. The required steps: 1) Create a new cake app in localhost root named blog. 2) Create the blog’s database. 3) Create five tables: users, posts, comments, tags, posts_tags. 4) Create the models and specify the association relationship between them. 5) Create the controllers and test the association using scaffolding. Khalid Alharbi, © 2011 27
28.
Create the blog’s
database (I) users table: CREATE TABLE `users` ( `id` int(11) unsigned NOT NULL auto_increment, `name` varchar(100), `email` varchar(150),`firstname` varchar (60),`lastname` varchar(60),PRIMARY KEY (`id`)); posts table: CREATE TABLE `posts` ( `id` int(11) unsigned NOT NULL auto_increment, `name` varchar(255), `date` datetime, `content` text, `user_id` int(11), PRIMARY KEY (`id`), FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE ON UPDATE CASCADE ); comments table: CREATE TABLE `comments` ( `id` int(11) unsigned NOT NULL auto_increment, `name` varchar(100), `content` text, `post_id` int(11), PRIMARY KEY (`id`), FOREIGN KEY(post_id) REFERENCES posts(id) ON DELETE CASCADE ON UPDATE CASCADE ); Khalid Alharbi, © 2011 28
29.
Create the blog’s
database (II) tags table: CREATE TABLE `tags` ( `id` int(11) unsigned NOT NULL auto_increment, `name` varchar(100), `longname` varchar(255), PRIMARY KEY (`id`) ); posts_tags table: CREATE TABLE `posts_tags` ( `id` int(11) unsigned NOT NULL auto_increment, `post_id` int(11) unsigned, `tag_id` int(11) unsigned, PRIMARY KEY (`id`), FOREIGN KEY(post_id) REFERENCES posts(id) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY(tag_id) REFERENCES tags(id) ON DELETE CASCADE ON UPDATE CASCADE ); The naming convention for foreign keys is: [singular table name]_id Khalid Alharbi, © 2011 29
30.
Models and Association
User Model: /app/models/user.php Post Model: /app/models/post.php Tag Model: /app/models/tag.php Khalid Alharbi, © 2011 30
31.
Controllers and Scaffolding
Scaffolding is a technique for testing table associations without needing to code any HTML. To add scaffolding to the application, define the $scaffold variable in the controller. Posts Controller: /app/controllers/posts_controller.php Tags Controller: /app/controllers/posts_controller.php Khalid Alharbi, © 2011 31
32.
The Resulting Application
(I) Navigate to: http://localhost/blog/posts/add Khalid Alharbi, © 2011 32
33.
The Resulting Application
(II) Navigate to: http://localhost/blog/tags/add Khalid Alharbi, © 2011 33
34.
The Bake Script
The bake script is a shell script that automatically generates the basic elements of CakePHP. It saves a lot of time generating the needed controllers, models, views, and unit tests. It helps understand how MVC works in Cake. It is located in cake/console/libs/bake.php Configuring and using the bake script is illustrated in the following link: http://www.screencast.com/t/Lyr5li6btec Khalid Alharbi, © 2011 34
35.
Callback methods
Helps add special logic before or after actions are executed. Cake supports callback methods for both controllers and models. Controller callback methods: beforeFilter(), beforeRender(), afterFilter(), etc. Model callback methods: beforeFind(), afterFind(), beforeValidate(), beforeSave(), beforeDelete(), etc. Khalid Alharbi, © 2011 35
36.
Layouts
Contain the overall design that wraps a view. Layouts files must be placed in /app/views/layouts directory and named lowercase with .ctp extension. The variable $content_for_layout is used to place the code for the views. Khalid Alharbi, © 2011 36
37.
Routes
Mechanism that maps URLs to controller actions. Helps customize URLs and maintain the MVC structure. Helps generate non-HTML files such as PDFs, RSS feeds, etc. Cake comes configured with a default set of routes: Ex: Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); Routing configuration file is located in: /app/config/routes.php. Khalid Alharbi, © 2011 37
38.
Extending MVC Structure
Cake contains resources that extends the MVC structure while maintaining its lightweight organization. Cake has the following extensions: Helper: extends the View’s functionality. Component: extends the Controller’s functionality. Data Source: extends the Model’s functionality. Behavior: extends the Model’s functionality. Khalid Alharbi, © 2011 38
39.
Helpers
Classes for the presentation layer to extend the functionality of the views. Contain the presentation logic shared between views, elements, or layouts. Simplify rendering HTML and processing forms. CakePHP has a set of built in helpers: HTML, Form, AJAX, Cache, JavaScript, RSS, XML, sessions, Time, Text, etc. Ex: <?=$html->link('Add a Post','/posts/add');?> Ability to create custom helpers. Khalid Alharbi, © 2011 39
40.
Components
Used to extend the functionality of the controllers. Components are specific purpose shared actions that can be used across all controllers such as sending email, etc. Components are stored in the /app/controllers/ components directory. Cake comes with built-in components: Auth, Session, Cookie, Email, Security, etc. Ability to create custom controllers. Khalid Alharbi, © 2011 40
41.
Data Sources
Connect to extra data-sources and provide data to the models. Models can reference functions in the DataSource without performing extra connections and data handling operations. Cake comes with built-in DataSources that support only relational database systems. Ability to create custom data sources and connect to REST APIs. Khalid Alharbi, © 2011 41
42.
Behaviors
Extend the functionality of models without writing a set of functions in the models. Keep repetitive tasks in separate resource file and allow models to access it. Example: when updating a record in the database, perform many updates across the database. Cake comes with built-in behaviors: ACL, Containable, Translate, and Tree. Ability to create custom behaviors. Khalid Alharbi, © 2011 42
43.
Utilities
General-purpose libraries that can be called from anywhere in the app through the App::import() function. Cake comes with built-in utilities: Configure: storing global variables. File and Folder: managing file and folder operations. HTTP Socket: managing requests to web services. Khalid Alharbi, © 2011 43
44.
Plugins
Mini-cake application inside other Cake app. Plugins are useful as third-party resources. Plugins contain models, views, and controllers just like any Cake application. Plugins are droped into the app/plugins directory. No built-in plugins in Cake only third-party plugins. Ability to create custom plugins so they can be used by other applications. Khalid Alharbi, © 2011 44
45.
Cake Community (I)
Cookbook – http://book.cakephp.org Official CakePHP documentation. Bakery - http://bakery.cakephp.org Official CakePHP community portal. API - http://api.cakephp.org All questions at CakePHP- http://ask.cakephp.org Official questions and answers website. CakePHP TV - http://tv.cakephp.org Free video tutorials. Khalid Alharbi, © 2011 45
46.
Cake Community (II)
CakeFest - http://cakefest.org The CakePHP conference. CakeForge - http://cakeforge.org Hosts open source CakePHP projects. CakePackages - http://www.cakepackages.com Free CakePHP code to download. GitHub – https://github.com/cakephp/cakephp Official CakePHP repository. Khalid Alharbi, © 2011 46
47.
References
Beginning CakePHP: From Novice to Professional By David Golding, ISBN: 1-4302-0977-1 CakePHP Application Development By Anupom Syam and Ahsanul Bari, ISBN: 9781847193896 CakePHP 1.3 Manual Book, http://book.cakephp.org CakePHP after 3 years, looking back and moving ahead by Gwoo http://bakery.cakephp.org/articles/gwoo/2008/04/22/ after-3-years-looking-back-and-moving-ahead Khalid Alharbi, © 2011 47
48.
Thank You! Khalid Alharbi,
© 2011 48
Jetzt herunterladen