使用codeigniter框架

时间:2016-09-19 10:25:30

标签: php html codeigniter

我创建了后端功能,用于添加页脚数据并在前端显示页脚数据。但是,获取数据并显示数据仅适用于index.php页面,但不适用于剩余页面。在剩下的页面中获取php错误消息:

  

未定义的属性:stdClass :: $ get_in_touch。

我创建了一个数据库,并将标题图像和页脚数据存储在一个表中。因此,获取它不适用于其他页面。这是我的代码:

欢迎(这是我的索引页面控制器):

public function index()
{
    $this->load->model('index_model');
    $data['records2'] = $this->index_model->get_all_client_images();
    $data['mainpage'] = "index";
    $this->load->view('templates/template',$data);
}

推荐控制器(我无法显示页脚数据导致php错误。):

public function index()
{

    $this->load->model('testimonial_model');
    $data['records2'] = $this->testimonial_model->get_all_testimonials();
    $data['mainpage'] = "testimonial";
    $this->load->view('templates/template',$data);
}

模型(Index_model):

function get_all_client_images()
{

    $this->db->select('B.*');
    $this->db->from('banner AS B');
    $q = $this->db->get();
    if($q->num_rows()>0)
    {
        return $q->result();
    }
    else 
    {
        return false;
    }
}

testimonial_model:

function get_all_testimonials()
{

    $this->db->select('T.*');
    $this->db->from('testimonials AS T');
    $this->db->where(array('T.status'=>1));
    $q = $this->db->get();
    if($q->num_rows()>0)
    {
        return $q->result();
    }
    else 
    {
        return false;
    }
}

footer.php

<?php if(isset($records2) && is_array($records2)):?>
            <?php foreach ($records2 as $r):?>
<div class="col-md-12">
                    <div class="col-sm-3 ">
                        <div class="footerWidget ">
                            <h3 class="getintouch">Get In Touch</h3>
                            <address>
                                <p>
                                    <?php echo $r->get_in_touch;?>
                                    Phone: +91-080-420-131-80 <br>
                                    Cell:+91-924-128-9345<br>
                                    <a href="mailto:info@teknotrait.com" class="notification">Email: info@teknotrait.com</a>
                                </p>
                            </address>
                        </div>
                    </div>
                    <div class="col-sm-3 abouts">
                            <div class="footerWidget ">
                                <h3 class="ourcompany">Our Company</h3>
                                <?php echo $r->our_company;?>
                            </div>
                    </div>
                    <div class="col-sm-3 specializationss">
                            <div class="footerWidget ">
                                <h3 class="ourspecialization">Our Specialization</h3>
                                <?php echo $r->our_specialization;?>
                            </div>
                    </div>

1 个答案:

答案 0 :(得分:0)

<强>尝试

 $this->db->where('status','1');
$q = $this->db->get('testimonials');

而不是

 $this->db->select('T.*');
$this->db->from('testimonials AS T');
$this->db->where(array('T.status'=>1));
$q = $this->db->get();