Last active
July 31, 2020 23:25
-
-
Save jimgwhit/5dccf7035a29b33eaa7b to your computer and use it in GitHub Desktop.
This file contains 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
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