Вот моя вспомогательная функция в файле помощник misc_helper.php,Codeigniter модель показывает Undefined ошибка собственности на помощника
function echoEditorsPickItems($projects = array('02134444', '0314020000')) {
if (!is_null($projects)) {
$CI = &get_instance();
$CI->load->database();
$CI->load->model('Project');
$projects = $CI->Project->getAllProjects(); // this is the 28th line
// getAllProjects() returns
// an arrays of item
for ($i=0; $i<EDITORS_PICK_ITEM_LIMIT; $i++) {
// $CI->Project->getItem('0214010001');
$out = '';
$out .= '<li>';
$out .= '<span>';
$out .= '<a href="'. base_url() . 'portfolio/detail/' . $projects[$i]['pId'] .'" class="post-img">';
$out .= '<img src="'. base_url() . 'assets/img/blog/' . $projects[$i]['brandImageUrl'] . '" alt="' . $projects[$i]['title'] . '">';
$out .= '<span class="overlay"></span>';
$out .= '</a>';
$out .= '</span>';
$out .= '<p class="wrap">';
$out .= '<a href="'. base_url() . 'portfolio/detail/' . $projects[$i]['pId'] .'" class="rp_title">' . $projects[$i]['title'] . '</a>';
$out .= '<small class="rp_date">' . $CI->Project->title . '</small>';
$out .= '</p>';
$out .= '</li>';
echo $out;
}
}
}
Когда я называю его, я получаю следующее сообщение об ошибке,
Severity: Notice
Message: Undefined property: Project::$Project
Filename: helpers/misc_helper.php
Line Number: 28
Редактировать : Вот моя модель,
class Project extends CI_Controller {
private $tableName = DB_TABLE_NAME_PROJECT;
public $title;
public $description;
public $client;
public $skills;
public $preparedBy;
public $catagory;
public $date;
public $url;
public $images;
public $templateType;
function __construct() {
parent::__construct();
$this->load->database();
}
public function getItem($projectId = NULL) {
if (!is_null($projectId)) {
$res = $this->db->get_where($this->tableName, array('pId' => $projectId));
if ($res->num_rows) {
$this->title = $res->row(1)->title;
$this->description = $res->row(1)->description;
$this->client = $res->row(1)->client;
$this->preparedBy = $res->row(1)->preparedBy;
$this->skills = explode(TOKEN_DELIMINATOR, $res->row(1)->skills);
$this->catagory = $res->row(1)->catagory;
$this->date = $res->row(1)->date;
$this->url = $res->row(1)->url;
$this->images = explode(TOKEN_DELIMINATOR, $res->row(1)->images);
$this->templateType = ($res->row(1)->templateType=='1'? 1:0);
return TRUE;
}
return FALSE;
}
return FALSE;
}
public function getAllProjects() {
$res = $this->db->get($this->tableName);
$projects = array();
for ($i=0; $i<$res->num_rows(); $i++){
$projects[$i] = array();
$projects[$i]['title'] = $res->row($i)->title;
$projects[$i]['catagory'] = explode(TOKEN_DELIMINATOR, $res->row($i)->catagory);
$projects[$i]['brandImageUrl'] = $res->row($i)->brandImageUrl;
$projects[$i]['pId'] = $res->row($i)->pId;
}
return $projects;
}
}
Пробовал, не работал! – Dewsworld
что такое 28-я линия? –
Только что обновил мой оригинальный код с 28-й строкой – Dewsworld