遇到PHP错误严重性:警告消息:为foreach()提供的参数无效文件名:views / page_view.php行号:13

时间:2015-09-01 12:04:24

标签: php codeigniter foreach

<?php 
if(!defined('BASEPATH')) exit("No direct script access allowed");
class page_controller extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('page_model');
    }
    public function contact_info()
    {
        $config = array();
        $config["base_url"] = base_url() . "index.php/page_controller/contact_info";
        $total_row = $this->page_model->record_count();
        $config["total_rows"] = $total_row;
        $config["per_page"] = 1;
        $config["use_page_numbers"] = TRUE;
        $config["num_links"] = $total_row;
        $config["cur_tag_open"] = '&nbsp;<a class="current">';
        $config["cur_tag_close"] = '</a>';
        $config["next_link"] = 'Next';
        $config["prev_link"] = 'Previous';
        $this->pagination->initialize($config);
        if($this->uri->segment(3))
        {
            $page = ($this->uri->segment(3));
        }
        else
        {
            $page = 1;
        }
        $data["results"] = $this->page_model->fetch_data($config["per_page"], $page);
        $str_links = $this->pagination->create_links();
        $data["links"] = explode('&nbsp;', $str_links);
        $this->load->view('page_view', $data);
    }
}
?>  

1 个答案:

答案 0 :(得分:0)

您可以使用如下:

if (is_array($values) || is_object($values))
{
    foreach ($values as $value)
    {
    ...
    }
}