CodeIgniter无法找出错误未定义的变量?

时间:2018-04-14 20:28:49

标签: php codeigniter

这需要很长时间才能搞清楚。

错误

  

遇到严重错误:通知

     

消息:未定义的变量:galdata

     

文件名:admin / slidersetting.php

     

行号:90

控制器

public function homesliderimage()
{
    $this->load->helper('form');
    $galdata=$this->homecontentmodel->fetchsliderimg();
    $this->load->view('admin/slidersetting',['galdata'=>$galdata]);
}

视图

    if(count($galdata)){
            foreach($galdata as $gallerydata){
                ?>
            <div class="col-md-4">
            <img data-toggle="modal" data-target="#myModal<?php echo $gallerydata->id?>" src="<?php echo base_url().'/'.$gallerydata->bgimagepath;?>" class="img-responsive img-thumbnail">
            <div id="myModal<?php echo $gallerydata->id?>" class="modal fade" role="dialog">
             <div class="modal-dialog modal-lg">

                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                    </div>
                    <div class="modal-body">
                        <img src="<?php echo base_url().'/'.$gallerydata->imagepath;?>" class="img-responsive">
                    </div>
                        </div>

                         </div>
                        </div>
                        </div>

                        <?php
                        }
                    }
                    else
                    {
                        echo '<div class="alert alert-danger">
  <strong>Oops!</strong> No data found , Please insert something to show here.
</div>';

这是我的模特

 class Homecontentmodel extends CI_Model
 {


  public function insertslider($bnr)
  {
       return $this->db->insert('slider',$bnr);

  }
  public function fetchsliderimg()
  {
      $q = $this->db->get('slider');

     return $q->result();

  }

 }

使用..Var_dump($ galdata)显示的数组;返回;在视野中 这是使用var dump和return

之后的结果数组
array (size=3)
  0 => 
    object(stdClass)[20]
      public 'id' => string '1' (length=1)
      public 'imagepath' => string 'asset/images/dog-3091075_19201.jpg' (length=34)
      public 'textcontent' => string 'vcbcvbcvbc' (length=10)
      public 'alttext' => string 'dsf' (length=3)
      public 'priority' => string '0' (length=1)
  1 => 
    object(stdClass)[21]
      public 'id' => string '2' (length=1)
      public 'imagepath' => string 'asset/images/model.jpg' (length=22)
      public 'textcontent' => string 'xgxfgdf' (length=7)
      public 'alttext' => string 'dgdfgd' (length=6)
      public 'priority' => string '0' (length=1)
  2 => 
    object(stdClass)[22]
      public 'id' => string '3' (length=1)
      public 'imagepath' => string 'asset/images/nomoicard1.jpg' (length=27)
      public 'textcontent' => string 'rtertreerter' (length=12)
      public 'alttext' => string 'dfd' (length=3)
      public 'priority' => string '0' (length=1)

3 个答案:

答案 0 :(得分:1)

希望这会解决您的问题:

替换

with filtered as (
    select id, title
    from notifications 
    where title ilike '%a%'
)

select json_build_object(
    'total', (select count(*) from filtered), 
    'data', json_agg(to_json(t)))
from (
    select id, title
    from filtered
    order by id
    limit 2
    ) t

if(count($galdata)) {
}

或替换为

if(! empty($galdata)){
}

答案 1 :(得分:0)

在控制器中更改如下

$galdata['galdata']=$this->homecontentmodel->fetchsliderimg();
$this->load->view('admin/slidersetting',$galdata);

您使用的阵列符号不适用于最新的php(&gt; 5.4)版本

答案 2 :(得分:0)

将此添加到您的模型

span = 'M'
num_days = pd.Period(span).days

在控制器中更改

$this->load->database();