准备将 CakePHP 3.4 迁移到 CakePHP 4.0
Preparing to migrate CakePHP 3.4 to CakePHP 4.0
因为我们正在开始我的项目的第二部分。我们希望先完成迁移过程,然后再进行项目的下半部分。我对迁移过程有一些疑虑,想消除我的疑虑。
目前,在我的项目中,我们使用了很多下面提到的这些功能
- 我们是否必须将所有 $this->Form->input['description'] 替换为 $this->Form->控制['description']?
- 当您提到 Response::download() 时,将变为 Response::withDownload()。你的意思是我必须将 $this->response->download($filename) 更改为 $this->response->WithDownload($filename)?
- 我们的 Table.php 中有此代码行 $this->primaryKey('id') 并且您提到这是已弃用列表的一部分并已替换为 getX() 和 setX()方法。你那是什么意思?我希望你能给我一个例子。
在控制器中找到以下代码,我注意到您提到了 hydrate()(现在是 enableHydration() / isHydrationEnabled())。下面我们需要做哪些改动?
$CustomersordersTable-> find()
-> select(['order_id'=>'Customerorders.order_id'])
-> where(['id IN' => $studentlist])
-> hydrate(false)
-> toArray();
我也了解到 $this->request->data['id'] 已被弃用,我们需要 $this->request->getData('id') .但是,在添加细节时,现在我们不能为这个 $this->request->getData('id') 分配一个随机的 id 值。在保存到 table.
之前,我曾经使用以下内容分配一个随机 ID
$this->request->data['id'] = TableRegistry::get('Customers')->find('guid');
你有 CakePHP 4.0 的暂定发布日期吗?
- 是
- 是
- 很简单,就是用set方法设置一个值,get获取一个值。像 setTable($name).
- 启用保湿()
- 不应该直接修改请求数据。不是在 3.4 之前,也不是在 3.4 之后。从请求中获取数据,修改它,做任何你想做的事。 3.4中的请求对象是immutable.
CakePHP4 没有发布日期,只有 roadmap 没有任何日期。 CakePHP 是由志愿者开发的,所以只要人们有时间和心情就可以完成工作。欢迎投稿。 :)
5.
$guid = TableRegistry::get('Customers')->find('guid');
$newData = $this->request->withData('id', $guid);
//获取新的请求数据
$newData->getData('id');
因为我们正在开始我的项目的第二部分。我们希望先完成迁移过程,然后再进行项目的下半部分。我对迁移过程有一些疑虑,想消除我的疑虑。
目前,在我的项目中,我们使用了很多下面提到的这些功能
- 我们是否必须将所有 $this->Form->input['description'] 替换为 $this->Form->控制['description']?
- 当您提到 Response::download() 时,将变为 Response::withDownload()。你的意思是我必须将 $this->response->download($filename) 更改为 $this->response->WithDownload($filename)?
- 我们的 Table.php 中有此代码行 $this->primaryKey('id') 并且您提到这是已弃用列表的一部分并已替换为 getX() 和 setX()方法。你那是什么意思?我希望你能给我一个例子。
在控制器中找到以下代码,我注意到您提到了 hydrate()(现在是 enableHydration() / isHydrationEnabled())。下面我们需要做哪些改动?
$CustomersordersTable-> find() -> select(['order_id'=>'Customerorders.order_id']) -> where(['id IN' => $studentlist]) -> hydrate(false) -> toArray();
我也了解到 $this->request->data['id'] 已被弃用,我们需要 $this->request->getData('id') .但是,在添加细节时,现在我们不能为这个 $this->request->getData('id') 分配一个随机的 id 值。在保存到 table.
之前,我曾经使用以下内容分配一个随机 ID$this->request->data['id'] = TableRegistry::get('Customers')->find('guid');
你有 CakePHP 4.0 的暂定发布日期吗?
- 是
- 是
- 很简单,就是用set方法设置一个值,get获取一个值。像 setTable($name).
- 启用保湿()
- 不应该直接修改请求数据。不是在 3.4 之前,也不是在 3.4 之后。从请求中获取数据,修改它,做任何你想做的事。 3.4中的请求对象是immutable.
CakePHP4 没有发布日期,只有 roadmap 没有任何日期。 CakePHP 是由志愿者开发的,所以只要人们有时间和心情就可以完成工作。欢迎投稿。 :)
5.
$guid = TableRegistry::get('Customers')->find('guid');
$newData = $this->request->withData('id', $guid);
//获取新的请求数据
$newData->getData('id');