在视图中使用来自 baseController 的 object 变量时出现错误
when using object variable from baseController in view i get an error
我想在 codeigniter baseController 中使用自定义变量稍后在前端视图中设置 bootstrap 设置
尝试显示主题集的标题(深色)时出现此错误:
Notice: Trying to get property 'title' of non-object in
App\Views\index.php
感谢您的帮助(我是php的新手,请说明错误所在)
BaseController.php
public $pageSettings = [
'dark' => [
'title' => 'Dark Site Title',
'navigation' => true,
],
'light' => [
'title' => 'Light Site Title',
'navigation' => false
]
];
public $bootstrapTheme = 'dark';
public function view($page = 'home')
{
$data['theme'] = $this->bootstrapTheme;
$data['pageSettings'] = $this->pageSettings; // <-- HERE I set the obj variable
echo view('templates/index', $data);
}
View\index.php
<html>
<head>
<title><?php echo $pageSettings[$theme]->title;?></title>
</head>
您正在 index.php
中将 数组作为对象访问
改变这个:
echo $pageSettings[$theme]->title;
收件人:
echo $pageSettings[$theme]['title'];
我想在 codeigniter baseController 中使用自定义变量稍后在前端视图中设置 bootstrap 设置
尝试显示主题集的标题(深色)时出现此错误:
Notice: Trying to get property 'title' of non-object in App\Views\index.php
感谢您的帮助(我是php的新手,请说明错误所在)
BaseController.php
public $pageSettings = [
'dark' => [
'title' => 'Dark Site Title',
'navigation' => true,
],
'light' => [
'title' => 'Light Site Title',
'navigation' => false
]
];
public $bootstrapTheme = 'dark';
public function view($page = 'home')
{
$data['theme'] = $this->bootstrapTheme;
$data['pageSettings'] = $this->pageSettings; // <-- HERE I set the obj variable
echo view('templates/index', $data);
}
View\index.php
<html>
<head>
<title><?php echo $pageSettings[$theme]->title;?></title>
</head>
您正在 index.php
中将 数组作为对象访问改变这个:
echo $pageSettings[$theme]->title;
收件人:
echo $pageSettings[$theme]['title'];