CI框架给视图添加动态数据_php实例

WBOY
Release: 2016-06-07 17:15:09
Original
882 people have browsed it

数据通过控制器以一个数组或是对象的形式传入视图 , 这个数组或对象作为视图载入函数的第二个参数如果你使用一个对象,那么类变量将转换为数组元素。好了,让我们用你的控制器试试。打开控制器并添加以下代码

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

现在,打开你的视图文件,将其中的文本替换成与数组对应的变量:注意才前台页面取值时,直接用$key值,而不是$data

 <br> <br><title></title> <br> <br> <br> <h1></h1> <br> <br>
Copy after login

总结:当传递的是类变量$data的时候,那么它会转换为数组元素


方法很简单,需要的小伙伴自由发挥下,加入到自己的项目中去就可以了。

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!