CakePHP3でデータ保存前に特定の値をセットする
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
[[CakePHP3めも]]
bakeで生成されるContollerのコードでは以下のようになると思...
public function add()
{
$user = $this->Users->newEntity();
if ($this->request->is('post')) {
$user = $this->User->patchEntity($user, $thi...
if ($this->Users->save($user)) {
$this->Flash->success(__('The user has b...
return $this->redirect(['action' => 'ind...
} else {
$this->Flash->error(__('The user could n...
}
}
$this->set(compact('user'));
$this->set('_serialize', ['user']);
}
save でデータが登録されますが、この時にフォームから送信さ...
その場合は patchEntity を当てる前にデータをセットします。
public function add()
{
$user = $this->Users->newEntity();
if ($this->request->is('post')) {
$user->user_id = $this->Auth->user('id'); ...
$user = $this->User->patchEntity($user, $thi...
if ($this->Users->save($user)) {
$this->Flash->success(__('The user has b...
return $this->redirect(['action' => 'ind...
} else {
$this->Flash->error(__('The user could n...
}
}
$this->set(compact('user'));
$this->set('_serialize', ['user']);
}
終了行:
[[CakePHP3めも]]
bakeで生成されるContollerのコードでは以下のようになると思...
public function add()
{
$user = $this->Users->newEntity();
if ($this->request->is('post')) {
$user = $this->User->patchEntity($user, $thi...
if ($this->Users->save($user)) {
$this->Flash->success(__('The user has b...
return $this->redirect(['action' => 'ind...
} else {
$this->Flash->error(__('The user could n...
}
}
$this->set(compact('user'));
$this->set('_serialize', ['user']);
}
save でデータが登録されますが、この時にフォームから送信さ...
その場合は patchEntity を当てる前にデータをセットします。
public function add()
{
$user = $this->Users->newEntity();
if ($this->request->is('post')) {
$user->user_id = $this->Auth->user('id'); ...
$user = $this->User->patchEntity($user, $thi...
if ($this->Users->save($user)) {
$this->Flash->success(__('The user has b...
return $this->redirect(['action' => 'ind...
} else {
$this->Flash->error(__('The user could n...
}
}
$this->set(compact('user'));
$this->set('_serialize', ['user']);
}
ページ名: