Home > Backend Development > PHP Tutorial > CI框架中怎么给前台模板文件相应位置赋值,不借用smarty情况下?

CI框架中怎么给前台模板文件相应位置赋值,不借用smarty情况下?

WBOY
Release: 2016-06-06 20:44:37
Original
1225 people have browsed it

CI框架中怎么给前台模板文件相应位置赋值,不借用smarty情况下?

回复内容:

CI框架中怎么给前台模板文件相应位置赋值,不借用smarty情况下?

建议先看看CI的文档。

CI本身具有MVC的功能,是可以不通过Smarty来显示前台的模板文件的。
在controller里view你需要显示的视图,并为其传递一个数组。然后在前台模板相应的位置echo这个数组里的键值就行了。

文档里的一个例子
controller文件

<code class="lang-php"><?php class Blog extends CI_Controller {

 function index()
 {
  $data['title'] = "My Real Title";
  $data['heading'] = "My Real Heading";
  
  $this->load->view('blogview', $data);
 }
}
?>   
</code>
Copy after login

View文件(前台文件)

<code class="lang-php">

<title><?php echo $title;?></title>




<h1><?php echo $heading;?></h1>



  
</code>
Copy after login

看看文档
http://codeigniter.org.cn/user_guide/tutorial/news_section.html

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template