【问题标题】:Cakephp3 - Cant find $theme property that throws an errorCakephp 3 - 找不到引发错误的 $theme 属性
【发布时间】:2016-08-22 19:06:59
【问题描述】:

我已从 Cakephp3 v3 升级到 v3.3(使用 Composer),但出现以下错误:

Deprecated (16384): Property $theme is deprecated.
Use $this->viewBuilder()->theme() instead in beforeRender().
[CORE/src/View/ViewVarsTrait.php, line 103]

但我在我的文件中找不到使用 $theme 的位置。我在所有文件中搜索了关键字 $themebeforeRender,没有相关结果。

这个错误出现在我的所有页面中,所以它必须是每个页面中都包含的某个文件。

我已经在google上搜索过这个问题,也没有相关结果。

有其他人遇到过这个问题吗?

完整的错误堆栈:

$viewClass = null
$builder = object(Cake\View\ViewBuilder) {
	[protected] _templatePath => 'Users'
	[protected] _template => 'login'
	[protected] _plugin => null
	[protected] _theme => 'Orange'
	[protected] _layout => null
	[protected] _autoLayout => null
	[protected] _layoutPath => null
	[protected] _name => null
	[protected] _className => null
	[protected] _options => []
	[protected] _helpers => []
}
$validViewOptions = [
	(int) 0 => 'passedArgs'
]
$viewOptions = [
	'passedArgs' => []
]
$option = 'passedArgs'
$this = object(App\Controller\UsersController) {
	theme => 'Orange'
	name => 'Users'
	helpers => []
	request => object(Cake\Network\Request) {}
	response => object(Cake\Network\Response) {}
	paginate => []
	autoRender => false
	components => []
	View => null
	plugin => null
	passedArgs => []
	modelClass => 'Users'
	viewClass => null
	viewVars => []
	Flash => object(Cake\Controller\Component\FlashComponent) {}
	Auth => object(Cake\Controller\Component\AuthComponent) {}
	[protected] _responseClass => 'Cake\Network\Response'
	[protected] _components => object(Cake\Controller\ComponentRegistry) {}
	[protected] _validViewOptions => [
		(int) 0 => 'passedArgs'
	]
	[protected] _eventManager => object(Cake\Event\EventManager) {}
	[protected] _eventClass => '\Cake\Event\Event'
	[protected] _tableLocator => object(Cake\ORM\Locator\TableLocator) {}
	[protected] _modelFactories => [
		'Table' => [
			[maximum depth reached]
		]
	]
	[protected] _modelType => 'Table'
	[protected] _viewBuilder => object(Cake\View\ViewBuilder) {}
}
$deprecatedOptions = [
	'layout' => 'layout',
	'view' => 'template',
	'theme' => 'theme',
	'autoLayout' => 'autoLayout',
	'viewPath' => 'templatePath',
	'layoutPath' => 'layoutPath'
]
$new = 'theme'
$old = 'theme'

Cake\Controller\Controller::createView() - CORE/src/View/ViewVarsTrait.php, line 103
Cake\Controller\Controller::render() - CORE/src/Controller/Controller.php, line 616
Cake\Http\ActionDispatcher::_invoke() - CORE/src/Http/ActionDispatcher.php, line 131
Cake\Http\ActionDispatcher::dispatch() - CORE/src/Http/ActionDispatcher.php, line 99
Cake\Routing\Dispatcher::dispatch() - CORE/src/Routing/Dispatcher.php, line 65
[main] - ROOT/webroot/index.php, line 21

【问题讨论】:

  • 这是完整的错误信息吗?你在使用任何插件吗?可能是插件组件中的问题
  • @arilia 我没有使用插件,是的,这是完整的错误信息。
  • 您不必搜索关键字$theme,因为它曾经是控制器对象的属性。搜索 theme->theme。我会查看我的 AppController 或我的组件,idf any
  • 通常,如果您单击错误消息标题(已弃用...),您将看到整个错误堆栈以及触发该错误的确切行
  • “橙色”主题从何而来?我可以在 UsersController 或 AppController 中复制您的确切错误设置 public $theme = 'Orange';

标签: cakephp-3.x


【解决方案1】:

事实证明,在 AppController 中,需要将自定义主题(在我的情况下为橙色)声明为:

public function beforeRender(Event $event)
{
    $this->viewBuilder()->theme('Orange');
}

不喜欢

public $theme = 'Orange';

非常感谢 @arilia 帮助我解决这个问题。

【讨论】:

    猜你喜欢
    • 2019-02-06
    • 2019-03-08
    • 2014-06-24
    • 1970-01-01
    • 2020-08-25
    • 2017-09-10
    • 2013-02-07
    • 2018-06-13
    • 2021-04-09
    相关资源
    最近更新 更多