cakephp - $this->viewPath 不适用于 CakePHP 3.1

标签 cakephp cakephp-3.1

我已通过 Composer 将 cakePHP 应用程序更新到 3.1,并且正在尝试修复所有小警告或已弃用的警告。

我可以轻松修复 $this->layout 内容,但我不明白如何修复 viewPath 错误。

查看migration guide看起来应该是完全相同的东西:

$this->viewPath = 'Element';

应该变成

$this->viewBuilder()->viewPath('Element');

但这不起作用,我得到的唯一结果是

Error: Call to undefined method Cake\View\ViewBuilder::viewPath() 
File /var/www/myapp/src/Controller/InvoicesController.php 
Line: 375

解决这个问题的正确方法是什么?

最佳答案

来自完全相同的迁移指南,在其“查看”部分:

View::$viewPath is deprecated. You should use View::templatePath() instead.

猜猜现在是:

$this->viewBuilder()->templatePath('Element');

关于cakephp - $this->viewPath 不适用于 CakePHP 3.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32690074/

相关文章:

validation - CakePHP3 中令人困惑的验证与应用程序规则

mysql - cakephp 3.1 mysql 已经消失

cakephp - 无法使用 cakePHP html 助手添加 css 版本控制

php - CakePHP 可以从模型的 _schema 属性生成我的数据库表吗?

sql - 在 CakePHP 3 的 COUNT 中使用 DISTINCT

php - 干预图像 : Save image directly from an url with original file name and ext?

cakephp - cakePHP 3.4 中的登录重定向

php - Cake 无法连接到数据库

cakephp - 如何在 cakePHP 2.0 中的其他 Controller 操作中从 AppController beforeFilter 获取变量