1. 程式人生 > >thinkphp實現獲取某一條資料,前端頁面獲取這條資料時不用遍歷獲取值,直接呼叫這條資料

thinkphp實現獲取某一條資料,前端頁面獲取這條資料時不用遍歷獲取值,直接呼叫這條資料

首先獲取這條資料的id值:

$cate_id = (int) $this->_param('cate_id');

其次:獲取屬於這個id值的那條資料(根據前端需要獲取這條資料的那個欄位,$cate_name)

$cate_name = D('ele_cate')->where(array('cate_id' => $cate_id))->getField('cate_name');

再而:

$this->assign('cate_name', $cate_name);

前端獲取值:

<div class="top-title"><{$cate_name}></div>