Created
October 12, 2016 01:47
-
-
Save markstory/2e2f62d0ee66006ec0af32fad29edfef to your computer and use it in GitHub Desktop.
bake output for #9576
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Model\Entity; | |
use Cake\ORM\Entity; | |
/** | |
* Car Entity | |
* | |
* @property string $id | |
* @property string $name | |
* @property \Cake\I18n\Time $created | |
* @property \Cake\I18n\Time $updated | |
* | |
* @property \App\Model\Entity\Pilot[] $pilots | |
*/ | |
class Car extends Entity | |
{ | |
/** | |
* Fields that can be mass assigned using newEntity() or patchEntity(). | |
* | |
* Note that when '*' is set to true, this allows all unspecified fields to | |
* be mass assigned. For security purposes, it is advised to set '*' to false | |
* (or remove it), and explicitly make individual fields accessible as needed. | |
* | |
* @var array | |
*/ | |
protected $_accessible = [ | |
'*' => true, | |
'id' => false | |
]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Controller; | |
use App\Controller\AppController; | |
/** | |
* Cars Controller | |
* | |
* @property \App\Model\Table\CarsTable $Cars | |
*/ | |
class CarsController extends AppController | |
{ | |
/** | |
* Index method | |
* | |
* @return \Cake\Network\Response|null | |
*/ | |
public function index() | |
{ | |
$cars = $this->paginate($this->Cars); | |
$this->set(compact('cars')); | |
$this->set('_serialize', ['cars']); | |
} | |
/** | |
* View method | |
* | |
* @param string|null $id Car id. | |
* @return \Cake\Network\Response|null | |
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. | |
*/ | |
public function view($id = null) | |
{ | |
$car = $this->Cars->get($id, [ | |
'contain' => ['Pilots'] | |
]); | |
$this->set('car', $car); | |
$this->set('_serialize', ['car']); | |
} | |
/** | |
* Add method | |
* | |
* @return \Cake\Network\Response|void Redirects on successful add, renders view otherwise. | |
*/ | |
public function add() | |
{ | |
$car = $this->Cars->newEntity(); | |
if ($this->request->is('post')) { | |
$car = $this->Cars->patchEntity($car, $this->request->data); | |
if ($this->Cars->save($car)) { | |
$this->Flash->success(__('The car has been saved.')); | |
return $this->redirect(['action' => 'index']); | |
} else { | |
$this->Flash->error(__('The car could not be saved. Please, try again.')); | |
} | |
} | |
$this->set(compact('car')); | |
$this->set('_serialize', ['car']); | |
} | |
/** | |
* Edit method | |
* | |
* @param string|null $id Car id. | |
* @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise. | |
* @throws \Cake\Network\Exception\NotFoundException When record not found. | |
*/ | |
public function edit($id = null) | |
{ | |
$car = $this->Cars->get($id, [ | |
'contain' => [] | |
]); | |
if ($this->request->is(['patch', 'post', 'put'])) { | |
$car = $this->Cars->patchEntity($car, $this->request->data); | |
if ($this->Cars->save($car)) { | |
$this->Flash->success(__('The car has been saved.')); | |
return $this->redirect(['action' => 'index']); | |
} else { | |
$this->Flash->error(__('The car could not be saved. Please, try again.')); | |
} | |
} | |
$this->set(compact('car')); | |
$this->set('_serialize', ['car']); | |
} | |
/** | |
* Delete method | |
* | |
* @param string|null $id Car id. | |
* @return \Cake\Network\Response|null Redirects to index. | |
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. | |
*/ | |
public function delete($id = null) | |
{ | |
$this->request->allowMethod(['post', 'delete']); | |
$car = $this->Cars->get($id); | |
if ($this->Cars->delete($car)) { | |
$this->Flash->success(__('The car has been deleted.')); | |
} else { | |
$this->Flash->error(__('The car could not be deleted. Please, try again.')); | |
} | |
return $this->redirect(['action' => 'index']); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Model\Table; | |
use Cake\ORM\Query; | |
use Cake\ORM\RulesChecker; | |
use Cake\ORM\Table; | |
use Cake\Validation\Validator; | |
/** | |
* Cars Model | |
* | |
* @property \Cake\ORM\Association\HasMany $Pilots | |
* | |
* @method \App\Model\Entity\Car get($primaryKey, $options = []) | |
* @method \App\Model\Entity\Car newEntity($data = null, array $options = []) | |
* @method \App\Model\Entity\Car[] newEntities(array $data, array $options = []) | |
* @method \App\Model\Entity\Car|bool save(\Cake\Datasource\EntityInterface $entity, $options = []) | |
* @method \App\Model\Entity\Car patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = []) | |
* @method \App\Model\Entity\Car[] patchEntities($entities, array $data, array $options = []) | |
* @method \App\Model\Entity\Car findOrCreate($search, callable $callback = null) | |
* | |
* @mixin \Cake\ORM\Behavior\TimestampBehavior | |
*/ | |
class CarsTable extends Table | |
{ | |
/** | |
* Initialize method | |
* | |
* @param array $config The configuration for the Table. | |
* @return void | |
*/ | |
public function initialize(array $config) | |
{ | |
parent::initialize($config); | |
$this->table('cars'); | |
$this->displayField('name'); | |
$this->primaryKey('id'); | |
$this->addBehavior('Timestamp'); | |
$this->hasMany('Pilots', [ | |
'foreignKey' => 'car_id' | |
]); | |
} | |
/** | |
* Default validation rules. | |
* | |
* @param \Cake\Validation\Validator $validator Validator instance. | |
* @return \Cake\Validation\Validator | |
*/ | |
public function validationDefault(Validator $validator) | |
{ | |
$validator | |
->uuid('id') | |
->allowEmpty('id', 'create'); | |
$validator | |
->allowEmpty('name'); | |
return $validator; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<nav class="large-3 medium-4 columns" id="actions-sidebar"> | |
<ul class="side-nav"> | |
<li class="heading"><?= __('Actions') ?></li> | |
<li><?= $this->Html->link(__('List Cars'), ['action' => 'index']) ?></li> | |
<li><?= $this->Html->link(__('List Pilots'), ['controller' => 'Pilots', 'action' => 'index']) ?></li> | |
<li><?= $this->Html->link(__('New Pilot'), ['controller' => 'Pilots', 'action' => 'add']) ?></li> | |
</ul> | |
</nav> | |
<div class="cars form large-9 medium-8 columns content"> | |
<?= $this->Form->create($car) ?> | |
<fieldset> | |
<legend><?= __('Add Car') ?></legend> | |
<?php | |
echo $this->Form->input('name'); | |
?> | |
</fieldset> | |
<?= $this->Form->button(__('Submit')) ?> | |
<?= $this->Form->end() ?> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<nav class="large-3 medium-4 columns" id="actions-sidebar"> | |
<ul class="side-nav"> | |
<li class="heading"><?= __('Actions') ?></li> | |
<li><?= $this->Form->postLink( | |
__('Delete'), | |
['action' => 'delete', $car->id], | |
['confirm' => __('Are you sure you want to delete # {0}?', $car->id)] | |
) | |
?></li> | |
<li><?= $this->Html->link(__('List Cars'), ['action' => 'index']) ?></li> | |
<li><?= $this->Html->link(__('List Pilots'), ['controller' => 'Pilots', 'action' => 'index']) ?></li> | |
<li><?= $this->Html->link(__('New Pilot'), ['controller' => 'Pilots', 'action' => 'add']) ?></li> | |
</ul> | |
</nav> | |
<div class="cars form large-9 medium-8 columns content"> | |
<?= $this->Form->create($car) ?> | |
<fieldset> | |
<legend><?= __('Edit Car') ?></legend> | |
<?php | |
echo $this->Form->input('name'); | |
?> | |
</fieldset> | |
<?= $this->Form->button(__('Submit')) ?> | |
<?= $this->Form->end() ?> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<nav class="large-3 medium-4 columns" id="actions-sidebar"> | |
<ul class="side-nav"> | |
<li class="heading"><?= __('Actions') ?></li> | |
<li><?= $this->Html->link(__('New Car'), ['action' => 'add']) ?></li> | |
<li><?= $this->Html->link(__('List Pilots'), ['controller' => 'Pilots', 'action' => 'index']) ?></li> | |
<li><?= $this->Html->link(__('New Pilot'), ['controller' => 'Pilots', 'action' => 'add']) ?></li> | |
</ul> | |
</nav> | |
<div class="cars index large-9 medium-8 columns content"> | |
<h3><?= __('Cars') ?></h3> | |
<table cellpadding="0" cellspacing="0"> | |
<thead> | |
<tr> | |
<th scope="col"><?= $this->Paginator->sort('id') ?></th> | |
<th scope="col"><?= $this->Paginator->sort('name') ?></th> | |
<th scope="col"><?= $this->Paginator->sort('created') ?></th> | |
<th scope="col"><?= $this->Paginator->sort('updated') ?></th> | |
<th scope="col" class="actions"><?= __('Actions') ?></th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php foreach ($cars as $car): ?> | |
<tr> | |
<td><?= h($car->id) ?></td> | |
<td><?= h($car->name) ?></td> | |
<td><?= h($car->created) ?></td> | |
<td><?= h($car->updated) ?></td> | |
<td class="actions"> | |
<?= $this->Html->link(__('View'), ['action' => 'view', $car->id]) ?> | |
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $car->id]) ?> | |
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $car->id], ['confirm' => __('Are you sure you want to delete # {0}?', $car->id)]) ?> | |
</td> | |
</tr> | |
<?php endforeach; ?> | |
</tbody> | |
</table> | |
<div class="paginator"> | |
<ul class="pagination"> | |
<?= $this->Paginator->prev('< ' . __('previous')) ?> | |
<?= $this->Paginator->numbers() ?> | |
<?= $this->Paginator->next(__('next') . ' >') ?> | |
</ul> | |
<p><?= $this->Paginator->counter() ?></p> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment