CodeIgniter:未定义的变量


CodeIgniter : Undefined variable

我有这个问题

遇到PHP错误

严重性:注意

消息:Undefined variable: title

文件名:视图/content_home.php

行号:15

遇到PHP错误

严重性:注意

消息:未定义变量:text1

文件名:视图/content_home.php

行号:16

这是我的观点:

<div id="content">
<?php

    foreach($results as $row){
            $title = $row->title;
            $text1 = $row->text1;
            $text2 = $row->text2;
            $text3 = $row->text3;
            $text4 = $row->text4;
    }
    ?>
    <div id="leftHome">
            <h1><?php echo $title; ?></h1>
            <p> <?php echo $text1; ?> </p>
            <p><?php echo $text2; ?></p>        
    </div>
    <div id="rightHome">
            <h1><?php echo $text3; ?></h1>
            <ul>
                <li><a href="<?php echo base_url()?>site/food"><?php echo $text4; ?></a></li>
            </ul>
    </div>

here my controller:

public function home(){
    $this->load->model("model_get");
    $data["results"] = $this->model_get->getData("home");  
    $this->load->view("site_header");
    $this->load->view("site_nav");
    $this->load->view("content_home", $data);
    $this->load->view("site_footer");
    }

这里是模型

<?php
class Model_get extends CI_Model{
    function getData($page){
        $query = $this->db->get_where("pageData", array("title" =>$page));
        return $query->result();
    }
}

所有text1 - text4也未定义。我新的编码,我尝试任何东西,但仍然找不到问题。

为您的模型使用代码->

class Model_get extends CI_Model{
    function getData($page){
        $this->db->select('title, text1, text2, text3, text4');
        $query = $this->db->get_where("pageData", array("title" =>$page));
        //print_r($query->result());
        return $query->result();
    }
}

,然后print_r($results)进入您的视图文件,看看数据是否来自您的数据库为您的'title'和'text1'或不