introduction to cakephp
DESCRIPTION
The presentation is an introduction to cakePHP after our first project with cakePHP, we decided to share the knowledge.TRANSCRIPT
![Page 1: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/1.jpg)
CakePHP Framework
Cake chefs:
Mohamed Samir
Moustafa Badawy
![Page 2: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/2.jpg)
Agenda
• Introduction.
• MVC model of cakePHP.
• Folders structure and configurations.
• Controllers, Models and Views.
• Final look on the model.
• A big demo.
![Page 3: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/3.jpg)
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.
![Page 4: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/4.jpg)
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
![Page 5: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/5.jpg)
MVC (cont.)
http://www.example.com/cakes/buy
![Page 6: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/6.jpg)
MVC (cont.)http://www.example.com/cakes/buy
![Page 7: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/7.jpg)
Folder Structure
• Cakephp folder:
– App
– Cake [The core file of cake is here]
– Vendors [ Third-party PHP libraries is here]
– .htaccess
– index.php
– README
![Page 8: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/8.jpg)
Folder Structure (cont.)
• Any application:
![Page 9: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/9.jpg)
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
![Page 10: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/10.jpg)
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
![Page 11: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/11.jpg)
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
![Page 12: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/12.jpg)
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.
![Page 13: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/13.jpg)
Database Configurations
• Can be found at > app/config/database.php
![Page 14: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/14.jpg)
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.*
![Page 15: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/15.jpg)
Routes Configurations
• Found at > app/config/routes.php• Example:
![Page 16: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/16.jpg)
Enough Configurations :)
• Main components structure:
• Controller classes structure
• Model classes structure
• Views structure
![Page 17: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/17.jpg)
Controller classes structure
Controller
AppController
Any controller
shares its attributes and parameters with all its children controllers
![Page 18: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/18.jpg)
Controller classes structure
• Attributes:
• Interacting with views & Model:
Model Interaction
View Interaction
![Page 19: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/19.jpg)
Model classes structure
Model
AppModel
Any model
![Page 20: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/20.jpg)
Model classes structure
• Example:
![Page 21: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/21.jpg)
Views structure
• Example:
Header for all pages
Page content
Footer for all pages
![Page 22: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/22.jpg)
Final view before the Demo
Controller Model
View
data
23
1
6
5
4
Find()Save(data)
set(data)Render(view)
Logic
![Page 23: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/23.jpg)
Demo
Show time
![Page 24: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/24.jpg)
References
• http://book.cakephp.org
• http://aidanlister.com/2009/05/creating-a-community-in-five-minutes-with-cakephp/
![Page 25: Introduction to CakePHP](https://reader034.vdocuments.mx/reader034/viewer/2022052311/557a05c8d8b42a1c0a8b4c56/html5/thumbnails/25.jpg)
Thanks
Any Questions ?