Upload
mohamedsamirgalal
View
745
Download
2
Tags:
Embed Size (px)
DESCRIPTION
The presentation is an introduction to cakePHP after our first project with cakePHP, we decided to share the knowledge.
Citation preview
CakePHP Framework
Cake chefs:
Mohamed Samir
Moustafa Badawy
Agenda
• Introduction.
• MVC model of cakePHP.
• Folders structure and configurations.
• Controllers, Models and Views.
• Final look on the model.
• A big demo.
Introduction
• Cakephp = Free + OpenSource
• Some Features:
– Active, friendly community
– Compatible with versions 4 and 5 of PHP
– MVC architecture
– Built-in validation
– Works from any web site directory, with little to no Apache configuration involved.
MVC
• CakePHP follows the MVC software design pattern.
– The Model represents the application data
– The View renders a presentation of model data
– The Controller handles and routes requests made by the client
MVC (cont.)
http://www.example.com/cakes/buy
MVC (cont.)http://www.example.com/cakes/buy
Folder Structure
• Cakephp folder:
– App
– Cake [The core file of cake is here]
– Vendors [ Third-party PHP libraries is here]
– .htaccess
– index.php
– README
Folder Structure (cont.)
• Any application:
CakePHP Conventions
• Conventions => you may feel that it will waste your time while it is actually saving it !! ?
• Because it gives you free functionality
• Conventions for:
– Model and database
– Controller
– Views
CakePHP Conventions (cont.)
• Any PHP file > underscored• Like> any_file.php
• Any Class > CamelCased• Like> anyClass
• Model classes > singular and CamelCased• Like > Person, BigPerson
• Database tables > plural and underscored• Like> persons, big_persons
• Controllers> CamelCased, and end ‘Controller’• Like>PersonController
CakePHP Conventions (cont.)
• Database table: • "people"
• Model class: • "Person", found at /app/models/person.php
• Controller class:• "PeopleController", found at /app/controllers/people_controller.php
• View template, found at• /app/views/people/index.ctp
• Using these conventions, CakePHP knows that a request to http://example.com/people/ maps to a call on the index() function of the PeopleController, where the Person model is automatically available (and automatically tied to the ‘people’ table in the database), and renders to a file. None of these relationships have been configured by any means other than by creating classes and files that you’d need to create anyway
CakeConfiguration
• Configurations needed:
– Database configuration – To be able to connect a database to your application by giving
the parameters needed like username…etc
– Core configuration – Here you configure application settings like sessions,
caching,…etc
– Routes configurations– Here you configure how to parse a Url and what actions to
take then.
Database Configurations
• Can be found at > app/config/database.php
Core Configurations
Variable Description
debug 0 = Production mode. No output.1 = Show errors and warnings.2 = Show errors, warnings, and SQL.3 = Show errors, warnings, SQL, and complete controller dump.
Session.save -php = Use the default PHP session storage.-cake = Store session data in /app/tmp-database = store session data in a database table.
Cache.disable When set to true, caching is disabled site-wide.
Session.table The name of the table (not including any prefix) that stores session information.
Session.*
Routes Configurations
• Found at > app/config/routes.php• Example:
Enough Configurations :)
• Main components structure:
• Controller classes structure
• Model classes structure
• Views structure
Controller classes structure
Controller
AppController
Any controller
shares its attributes and parameters with all its children controllers
Controller classes structure
• Attributes:
• Interacting with views & Model:
Model Interaction
View Interaction
Model classes structure
Model
AppModel
Any model
Model classes structure
• Example:
Views structure
• Example:
Header for all pages
Page content
Footer for all pages
Final view before the Demo
Controller Model
View
data
23
1
6
5
4
Find()Save(data)
set(data)Render(view)
Logic
Demo
Show time
References
• http://book.cakephp.org
• http://aidanlister.com/2009/05/creating-a-community-in-five-minutes-with-cakephp/
Thanks
Any Questions ?