0
我已經在cakephp appcontrollet.php文件中創建了一個函數。這retrive我細節上從ID 的功能如下cakephp2.0 Appcontroller函數調用
function getDetail($id = null) // to check that user is valid or not
{
$data = $this->ModelName->find('first',array('conditions'=>array('ModelName.is_active'=>'Y','ModelName.is_deleted'=>'N','ModelName.primaryKey'=>$id)));
if($data !=array())
{
// return true;
return $data;
} else {
$data = array();
return $data;
//return false;
}
}
提到,記錄現在,我想從任何controlller調用這個函數來獲取記錄的細節像我都會調用這個函數弗朗Userscontroller,adminscontroller ,市場控制器等,它會返回我的相關數據
我的問題是,如何appcontroller知道請求來自哪個控制器和哪個模型用戶?
誰能幫我提前
是的,它的工作,但我怎麼能添加條件像'User.user_id'=> $ id或'Customer.customer_id'=> 4 .. –
在getDetails()你可以使用'$ this-> name'來獲得當前模型的名稱。因此,條件是'$ this-> name。'user_id'=> $ id'。 – mixable
是的,這是真的假設已從UsersControlle調用此功能,然後「$ this->名稱。」。user_id'=> $ id「這工作正常,但當這種funnction從另一個主控像CustomersController或CompaniesController調用.. –