Skip to content

Instantly share code, notes, and snippets.

@jimgwhit
Last active July 31, 2020 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimgwhit/5dccf7035a29b33eaa7b to your computer and use it in GitHub Desktop.
Save jimgwhit/5dccf7035a29b33eaa7b to your computer and use it in GitHub Desktop.
entity code:
<?php
namespace App\Model\Entity;
use Cake\ORM\Entity;
use Cake\Utility\Inflector;
/**
* Pet Entity.
*/
class Pet extends Entity
{
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* @var array
*/
protected $_accessible = [
'petname' => true,
'ownerid' => true,
'petowner' => true,
'species' => true,
'sex' => true,
'ostreet' => true,
'odate' => true,
'ocheck' => true,
'dogpic' => true,
];
protected function _setPetname($petname)
{
$this->set(strtoupper($petname));
return $petname;
}
}
controller code:
public function add()
{
$pet = $this->Pets->newEntity($this->request->data);
//////WHERE DO i SET THE VARIBLE $petname AND HOW DO I CALL THE SETTER AND DO I
/////NEED A GETTER AND A SETTER? MANUAL DOES NOT EXPLAIN WHAT TO DO.
if ($this->request->is('post')) {
if ($this->Pets->save($pet)) {
$this->Flash->success('The pet has been saved.');
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error('The pet could not be saved. Please, try again.');
}
}
$this->set(compact('pet'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment