Last active
June 14, 2018 17:34
-
-
Save hgnelson83/e4bb72ce0087fb049791b93439a7e801 to your computer and use it in GitHub Desktop.
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 Users'), ['action' => 'index']) ?></li> | |
<li><?= $this->Html->link(__('List Bookmarks'), ['controller' => 'Bookmarks', 'action' => 'index']) ?></li> | |
<li><?= $this->Html->link(__('New Bookmark'), ['controller' => 'Bookmarks', 'action' => 'add']) ?></li> | |
</ul> | |
</nav> | |
<div class="users form large-9 medium-8 columns content"> | |
<?= $this->Form->create($user, ['type' => 'file']) ?> | |
<fieldset> | |
<legend><?= __('Add User') ?></legend> | |
<?php | |
echo $this->Form->input('email'); | |
echo $this->Form->input('password'); | |
echo $this->Form->input('photo[]', ['type' => 'file', 'multiple' => 'true', 'label' => 'Add Some Photos']); | |
echo $this->Form->input('photo_dir', array('type' => 'hidden')); | |
?> | |
</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
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(__('The user has been saved.')); | |
return $this->redirect(['action' => 'index']); | |
} else { | |
$this->Flash->error(__('The user could not be saved. Please, try again.')); | |
} | |
} | |
$this->set(compact('user')); | |
$this->set('_serialize', ['user']); | |
} |
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 App\Model\Entity\User; | |
use Cake\ORM\Query; | |
use Cake\ORM\RulesChecker; | |
use Cake\ORM\Table; | |
use Cake\Validation\Validator; | |
/** | |
* Users Model | |
* | |
* @property \Cake\ORM\Association\HasMany $Bookmarks | |
*/ | |
class UsersTable extends Table | |
{ | |
/** | |
* Initialize method | |
* | |
* @param array $config The configuration for the Table. | |
* @return void | |
*/ | |
public function initialize(array $config) | |
{ | |
parent::initialize($config); | |
$this->table('users'); | |
$this->displayField('id'); | |
$this->primaryKey('id'); | |
$this->addBehavior('Josegonzalez/Upload.Upload', [ | |
'photo' | |
]); | |
$this->addBehavior('Timestamp'); | |
$this->hasMany('Bookmarks', [ | |
'foreignKey' => 'user_id' | |
]); | |
} | |
/** | |
* Default validation rules. | |
* | |
* @param \Cake\Validation\Validator $validator Validator instance. | |
* @return \Cake\Validation\Validator | |
*/ | |
public function validationDefault(Validator $validator) | |
{ | |
$validator | |
->integer('id') | |
->allowEmpty('id', 'create'); | |
$validator | |
->email('email') | |
->requirePresence('email', 'create') | |
->notEmpty('email'); | |
$validator | |
->requirePresence('password', 'create') | |
->notEmpty('password'); | |
return $validator; | |
} | |
/** | |
* Returns a rules checker object that will be used for validating | |
* application integrity. | |
* | |
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified. | |
* @return \Cake\ORM\RulesChecker | |
*/ | |
public function buildRules(RulesChecker $rules) | |
{ | |
$rules->add($rules->isUnique(['email'])); | |
return $rules; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment