Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introduction to CakePHP

2,628 views

Published on

The presentation is an introduction to cakePHP after our first project with cakePHP, we decided to share the knowledge.

Published in: Technology
  • Be the first to comment

Introduction to CakePHP

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

×