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

CakePHP: In about 15 minutes or less

CakePHP: In about 15 minutes or less

Run through of some basics with CakePHP in about 15 minutes for a framework roundtable.

Justin Yost

December 02, 2016
Tweet

More Decks by Justin Yost

Other Decks in Programming

Transcript

  1. CakePHP: In about 15 minutes or less Justin Yost Web

    Developer at Loadsys CC BY-NC 4.0 Justin Yost 1
  2. CakePHP Highlights — Convention over Configuration — MVC — "Build

    fast, grow solid" — PHP 5.5+ — ORM blends ActiveRecord and Datamapper CC BY-NC 4.0 Justin Yost 2
  3. CakePHP — composer create-project --prefer-dist cakephp/app {awesome-app} — Build Tables

    — Setup DB configuration — bin/cake bake all {table-name} — Done with CRUD for {table-name} CC BY-NC 4.0 Justin Yost 3
  4. CakePHP Core Classes — Table — Entity — View —

    Controller CC BY-NC 4.0 Justin Yost 5
  5. CakePHP: Table public function findOwnedBy(Query $query, array $options) { $user

    = $options['user']; return $query->where(['author_id' => $user->id]); } CC BY-NC 4.0 Justin Yost 6
  6. CakePHP: Entity protected function _getFullName() { return $this->_properties['first_name'] . '

    ' . $this->_properties['last_name']; } CC BY-NC 4.0 Justin Yost 7
  7. CakePHP: View <?php foreach ($users as $user): ?> <li class="user">

    <?= $this->element('user', ['user' => $user]) ?> </li> <?php endforeach; ?> CC BY-NC 4.0 Justin Yost 8
  8. CakePHP: Controller public function add() { $user = $this->Users->newEntity(); if

    ($this->request->is('post')) { $user = $this->Users->patchEntity($user, $this->request->data); if ($this->Users->save($user)) { $this->Flash->success(__('You are now registered.')); } else { $this->Flash->error(__('There were some problems.')); } } $this->set('user', $user); } CC BY-NC 4.0 Justin Yost 9
  9. Why I like CakePHP — Rich and extensive core foundational

    layer with lots of room to grow — ORM is amazing — Solid, Rich documentation CC BY-NC 4.0 Justin Yost 10