Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CakePHP 1.3 Intro

CakePHP 1.3 Intro

Talk geared toward introducing new users to how CakePHP 1.3 works.

Adam Culp

August 10, 2011
Tweet

More Decks by Adam Culp

Other Decks in Programming

Transcript

  1. Intro to CakePHP  South Florida PHP Users Group Adam

    Culp http://www.Geekyboy.com In this presentation we will cover an introduction to CakePHP which I hope will allow the participants to start experimenting on their own.
  2. Intro to CakePHP What is CakePHP? 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.
  3. Intro to CakePHP What? CakePHP is a framework of core

    stuff already done, that enables a developer to create things quickly! Thus saving themselves and companies time and money. Current version: 1.3 with 2.0 coming soon Runs on: PHP 4 and 5 up to 5.3 (recommended) Has a command line tool to automate code creation for both Windows and Linux.
  4. Intro to CakePHP Lets dig in! 1. Download CakePHP 2.

    Unzip 3. Setup Apache (or your favorite web server) 4. IT WORKS!!!
  5. Intro to CakePHP Structure • Cake is an OOP framework

    that utilizes an MVC design pattern. – Model = Data – View = Presentation – Controller = Logic and Direction • Config = settings files • Vendors = 3rd party and CRONs • Webroot = public – Contains the js, css, images • URL rewrite (.htaccess) makes it work
  6. Intro to CakePHP CakePHP conventions • Database table (plural) –

    products, categories • Controller naming (plural) – products_controller.php / ProductsController – categories_controller.php / CategoriesController • Model naming (singular) – product.php / Product – category.php / Category • View naming – products / index.ctp – category / index.ctp
  7. Intro to CakePHP Views keep design simple and easy •

    “Layout” = overall page appearance • “Elements” allow breaking up design elements from main layout. • “Pages” are handy for static content pages, where you don’t really need a controller or model. • “Routes” allow added rules to be created, and make Pages even more friendly to designers and SEO.
  8. Intro to CakePHP To Zend Studio >>> Set up basic

    public and admin layout, with element for header, footer, sidebar, and menu Also create base pages: Home, About, Contact
  9. Intro to CakePHP Take care of security and database •

    Initial screen prompts to “make it yours”. – Set Security.salt – Set Security.cipherseed – If PHP 5.3 set default timezone – Prefix Routing (admin, client) – Add a database • Rename ‘database.php.default’ to ‘database.php’ and customize…done! • >>> To Zend Studio
  10. Intro to CakePHP DB Field names and how CakePHP uses

    them: • Id –used as the primary key(UUID or int) • Name/Title – Cake will automatically map use this as a label in many circumstances. • Created – (datetime) Cake will automatically fill • Modified – (datetime) Cake will automatically fill • Foreign key fields = {model}_id (product_id, category_id) • >>> to phpmyadmin
  11. It does console too! • There is a very handy

    command line tool called “bake” that is a great code generation tool to get you started FAST! • Make sure to add the cake console to your operating systems PATH. – Windows = manual – Ubuntu = automated if cakephp installed with apt-get • >>> To the command prompt Intro to CakePHP
  12. Intro to CakePHP Tweaking • The “Look” by changing layout.

    • Adding ‘empty’ to dropdowns in the View. • Setting default values for checkboxes. • Using routes to simplify URLs. – Instead of ‘/pages/about’ we can use ‘/about’.
  13. Intro to CakePHP CRON jobs and Scheduled Tasks made easy

    • Create a php file in the ‘app/vendors/shells’. • The ‘main’ function is always run. • Kick off via command line, and get the benefits of the CakePHP framework. (models, etc.)
  14. Intro to CakePHP Resources • http://cakephp.org • http://book.cakephp.org • http://apachefriends.org

    • http://phpmyadmin.net • Come join us: Meetup, Facebook, LinkedIn – http://www.facebook.com/groups/128325450542999 – http://www.linkedin.com/groups?gid=3578819 – http://www.meetup.com/South-Florida-PHP-Users-Group