【问题标题】:link Pages in codeigniter在 codeigniter 中链接页面
【发布时间】:2014-08-22 19:13:03
【问题描述】:

我无法修复以下错误

遇到了 PHP 错误

严重性:通知

消息:未定义变量:结果

文件名:views/view_nav.php

行号:22

遇到了 PHP 错误

严重性:警告

消息:为 foreach() 提供的参数无效

文件名:views/view_nav.php

行号:22

这是我的代码

控制器

public function home(){
        $this->load->model('get_company_model');
        $this->load->view('view_header');
        $data['results'] = $this->get_company_model->get_all();

        $this->load->view('view_nav',$data);
        $this->load->view('view_content');
        $this->load->view('view_footer');
    }

型号

 public function get_All(){
        $query = $this->db->query("SELECT name,id from companydetails");
        return $query->result();

    }
    public function get_branch($companyID){
        $query = $this->db->query("SELECT name,id from branches WHERE companyid='".$companyID."'");
        return $query->result();

    }

查看

 <?php
    foreach($results as $row):
    ?>
    <div>
        <ol class="tree">
    <li>
        <label for="folder1"><a href="<?php echo site_url('site2/about'); ?>"><?=$row->name?></label></a> <input type="checkbox"  id="folder1" /> 
        <ol>
              <?php
                $myresult=$this->get_company_model->get_branch($row->id);
                foreach($myresult as $row2):
                  ?>  
            <li class="file"><a href="#"><?=$row2->name?></a></li>
            <?php
                 endforeach;
                ?>

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    您在Controller 中错误地定义了您的函数

       $data['results'] = $this->get_company_model->get_all();
                                                       ^It should be:
    
        $data['results'] = $this->get_company_model->get_All();
    

    注意大写A

    尝试在模型中回显查询以检查您的查询是否返回任何行。

    $query = $this->db->query("SELECT name,id from companydetails");
    echo $this->db->last_query();
    return $query->result();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-17
      • 2010-12-03
      • 2014-02-03
      • 1970-01-01
      • 2013-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多