未定义变量:行和如何在Codeigniter 3中显示图像滑块

时间:2016-08-14 11:23:14

标签: codeigniter

请帮助我...我正在学习CodeIgniter 3并且我遇到了这个错误。

我收到错误: 注意:未定义的变量:为foreach()提供的slid和Invalid参数。任何人都可以建议我解决这个问题吗?

控制器:home.php

  <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {

  function __construct()
  {
    parent::__construct(); 
  }
  
	function sliders(){
		
		$slider = $this->slider_model->get_slider();
         if ($slider){
          $data['slid'] = $slider;
         }
		$this->template->display('home',$data);
	}

}

型号:slider_model.php

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Slider_model extends CI_Model {

	function __construct()
    {
		parent::__construct();
	}
   
    function get_slider()
    {
      $r = $this->db->get('slider');
      $data = $r->result();
	  return $data;
    } 

}

查看:home.php

<div id="slider" class="fixed">
  <div class="background-slider"></div>
  <div class="background">
    <div class="shadow"></div>
    <div class="pattern">
      <div class="container" id="camera_1">
        <div class="camera_slider">
          <div class="spinner"></div>
          <div class="camera_wrap" id="camera_wrap_1" style="height: 465px">
            <?php foreach($slid as $r){ ?>
            <div><a href="#"><img src="<?php echo base_url();?><?php echo $r->image?> " alt="Slider"></a>
            </div>
            <?php } ?>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

这是Js的脚本

< script type = "text/javascript" >
  var camera_slider = $("#camera_wrap_1");

camera_slider.owlCarousel({
  slideSpeed: 300,
  lazyLoad: true,
  singleItem: true,
  autoPlay: 7000,
  stopOnHover: true,
  navigation: true
});

$(window).load(function() {
  $("#camera_1 .spinner").fadeOut(200);
  $("#camera_wrap_1").css("height", "auto");
}); < /script>

1 个答案:

答案 0 :(得分:0)

请尝试使用此代码

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {

  function __construct()
  {
    parent::__construct(); 
$this->load->model('slider_model');
  }

    function sliders(){

        $slider = $this->slider_model->get_slider();
         if ($slider){
          $data['slid'] = $slider;
         }
        $this->template->display('home',$data);
    }

}