Php 在模板中使用Page$数据变量
有没有办法在加载的模板中使用page$数据变量 例如,如果我有一个头部像这样的模板:Php 在模板中使用Page$数据变量,php,codeigniter,codeigniter-2,Php,Codeigniter,Codeigniter 2,有没有办法在加载的模板中使用page$数据变量 例如,如果我有一个头部像这样的模板: <!DOCTYPE html> <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> <head>
<!DOCTYPE html>
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<title><?php echo $data['title']; ?> | ACME, Inc.</title>
</head>
public function index($data) {
$data = array();
$data['title'] = 'Home';
$this->load->view('pages/home', $data);
}
如何获取父模板或同级视图以获取页面的变量?我通常使用下面的代码获取页面中的元数据 在控制器中:
$page = new stdClass();
$page->title = "Your Page Title";
$page->desc = "Your page description";
$page->key = "keword1,keyword2,keyword3";
$page ->author = "Alex";
$data['page'] = $page;
$this->load->view('pages/home', $data);
视图中:
<title><?php
if(isset($page->title)){
echo $page->title;
}
?></title>
<meta name="description" content="<?php
if(isset($page->desc)){
echo $page->desc;
}
?>"/>
<meta name="keywords" content="<?php
if(isset($page->key)){
echo $page->key;
}
?>"/>
<meta name="author" content="<?php
if(isset($page->author)){
echo $page->author;
}
?>"/>
content="<?php
if(isset($page->desc)){
echo $page->desc;
}
?>"/>
是否应该是
?您在哪里包含带有标题信息的视图?我有一个使用模板的页面。该模板有一个标题
视图,我希望将特定于页面的变量传递给该视图。请使用