我的控制器如下。
class Media extends CI_Controller
{
function __construct()
{
parent ::__construct();
$this->load->helper('url');
}
function get($folder_name)
{
$folder_name= "images/".$folder_name;
$this->load->library("Folder_functions");
$data = array("folders" => $this->folder_functions->folder_data($folder_name));
//$data= $this->folder_functions->folder_data($folder_name);
$this -> load -> view("display_folders", $data);
}
}
图书馆如下
class Folder_functions
{
function __construct()
{
$this->_ci =& get_instance();
$this->_ci->load->model("folder_model");
}
function folder_data($path)
{
$files1['name']= array();
$files1['image']= array();
$files1['name'] = scandir($path);
unset($files1['name'][0]);
unset($files1['name'][1]);
$del_val= 'Thumbs.db';
if(($key = array_search($del_val, $files1['name'])) !== false)
{
unset($files1['name'][$key]);
}
foreach ($files1 as $key => $value)
{
$results[] = $this->createObjectFromData($files1);
//echo $files1['name'];
}
return $results;
}
function createObjectFromData($files)
{
$files_obj = new Folder_Model();
$files_obj -> set_name($files['name']);
return $files_obj;
}
}
我的观点如下。
<?php
foreach ($folders as $values)
{
echo $values -> get_name();
echo '|';
}
?>
模型如下。
class Folder_Model extends CI_Model
{
public $name;
public $featured_image;
function __construct()
{
parent::__construct();
}
function set_name($folder_name)
{
$this -> name= $folder_name;
}
function set_featured_mage($image)
{
$this -> featured_image= $image;
}
function get_name()
{
return $this -> name;
}
function get_featured_mage()
{
return $this -> featured_image;
}
}
&GT;
我的问题是当我浏览code-igniter / index.php / media / get / MyFolder'url我在视图中收到错误“数组到字符串转换”echo $ values - &gt; GET_NAME()。我该如何解决此错误。请指导我。