我有一个未定义变量的问题。在view/somefolder/somefile.php
中,他们回应了一些变异(<?php echo $news;?>
)。我尝试了一切来找到这个变量的定义位置(在PHPStorm中的路径中查找),但没有结果。当我对print_r($GLOBALS)
进行测试时,我得到了
[_ci_cached_vars:protected] => Array
(
[unread] => 0
[unans] => 0
[ques_unread] => 0
[is_loged] =>
[level] =>
[avatar] => media/img/avatar.png
[username] =>
[root_cat] => 0
[logErr] =>
[radio_list] => Array
(
)
[entitet] => 1
[current_modul] => infograda
[tree] => <ul></ul>
[category] => stdClass Object
(
[id] => 153
[title] => HRONIKA
[description] =>
[parent_id] => 0
[order] => 52
[module] => infograda
[expanded] => 0
[content_type_id] => 1
)
[module] => infograda
[active] =>
[additionHtml] =>
[news] => Array
(
[0] => stdClass Object
(
[id] => 1574
[content_id] => 1574
[module] => infograda
[order] =>
[title] => Title
[text] => <div class="uvod_holder">
答案 0 :(得分:0)
从控制器加载视图。例如:
控制器:
// this file resides in application\controllers\mycontroller.php
class Mycontroller extends CI_Controller{
function mypage() {
$data = array('news' => 'some news');
$this->load->view('page', $data);// will load views\page.php and pass the $data array
}
}
查看
<!--this file resides in application\views\page.php -->
<html>
<head></head>
<body><?= $news; ?></body>
</html>
要做到这一点,您的网址会说http://localhost/index.php/mycontroller/mypage
(如果您在本地工作)
您的变量正在加载该视图的控制器中设置。