如何在codeigniter 3.0中自定义主模板概念?

时间:2016-07-18 06:15:32

标签: php codeigniter

我是Codeigniter 3.0的新手。所以主页面概念如何在Codeigniter 3中使用。

我想制作管理面板母版页,所以我不会重写页眉,页脚代码。我也想自定义标题。

怎么做?

1 个答案:

答案 0 :(得分:1)

首先,我会在控制器中创建如下所示的内容。您可以将内容页面设置为如下所示的变量,然后将其传递给管理模板。就像在示例视图中一样。下面只是一个例子。还自动加载url helper。

<?php

class Welcome extends CI_Controller {

   public function index() {
      // You should be able to pass data as normal

      $data['title'] = 'Welcome to CodeIgniter'; // You can change the title on every controller you create.

      $data['template_page'] = 'welcome_message'; // This dashboard would be name of a view and common name a folder.

      $this->load->view('template', $data);
   }

}

示例2控制器

<?php

class Dashboard extends CI_Controller {

   public function index() {
      // You should be able to pass data as normal

      $data['title'] = 'Dashboard'; // You can change the title on every controller you create.

      $data['template_page'] = 'common/dashboard'; // This dashboard would be name of a view and common name a folder.

      $this->load->view('template', $data);
   }

}

观看次数&gt;的template.php

<?php

$this->load->view('common/header');

$this->load->view($template_page);

$this->load->view('common/footer');

?>

标题视图&gt;常见&gt;的header.php

<!DOCTYPE html>
<html>
<head>
    // meta tags
    <title><?php echo $title;?></title>
    // css links
    // other js links
</head>

<body>

内容可以说明仪表板视图&gt;常见&gt; dashboard.php

 <h1>Hello World</h1>

页脚视图&gt;常见&gt; footer.php

// bootstrap scripts.
</body>
</html>