我是Cakephp的新手,从cake3开始.
我遇到的一个问题是,从性能意义上来说,哪种方法最适合在CakePHP-3.0中获取表的实例,而不是控制器在loadModel或TableRegistry之间的默认表.
如:
1. $this->loadModel('Articles');
OR
2. TableRegistry::get('Articles');
Run Code Online (Sandbox Code Playgroud)
我为loadModel和TableRegistry阅读了Cake-Doc .混乱来自这里
提前致谢
我想在Cakephp 3.0中更新或保存表的特定字段.我尝试从Cakebook 更新数据并保存数据,但问题是它还保存在数据库中指定为日期时间的修改字段.在这种情况下,我不想保存此字段.我怎么做?
提前致谢
我在 CakePHP 3.0 中面临使用 Form 将数据保存到数据库的问题。
//add.ctp
<div>
<?= $this->Form->create($deposit) ?>
<fieldset>
<legend><?= __('Add') ?></legend>
<?php
echo $this->Form->input('date');
echo $this->Form->input('profile_id', ['options' => $profiles]);
echo $this->Form->input('amnt');
echo $this->Form->input('desc');
echo $this->Form->input('user_id', ['options' => $users]);
?>
</fieldset>
<?= $this->Form->button(__('Submit')) ?>
<?= $this->Form->end() ?>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的添加功能
public function add()
{
$deposit = $this->Deposits->newEntity();
if ($this->request->is('post')) {
$deposit = $this->Deposits->patchEntity($deposit, $this->request->data);
if ($this->Deposits->save($deposit)) {
$this->Flash->success(__('The member deposit has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The member deposit could not be saved. Please, …Run Code Online (Sandbox Code Playgroud)