這裏是一個幫助文件misc_helper.php我的助手功能,笨模型顯示於輔助未定義的屬性錯誤
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