我已按照以下語法在會話中編寫了我的client.id
。CakePHP 2.6:會話讀取控制器不工作
$this->Session->write('Client.id', $client_id);
然後我就在view.ctp檢查它像下面的代碼
<pre><?php print_r($this->Session->read('Client.id')); ?> </pre>
這是印刷陣列id
。
現在在Controller
我試過下面的代碼來獲得會話client.id
。
$client_id = $this->Session->read('Client.id');
在這段時間我沒有得到$client_id
。有沒有任何錯誤。有誰可以幫助我嗎?
在這裏,我在評論中加入更多的代碼爲提
在用戶控制器我在登錄操作
if($user_role == 'client')
{
$user_email = $this->Auth->user('email');
$this->loadModel('Client');
$client_id = $this->Client->find('all',
array(
'conditions'=>array('Client.email'=>$user_email),
'fields' => array('Client.id'),
'limit' => 1,
'recursive' => -1, //int
)
);
$this->Session->write('Client.id', $client_id);
}
這裏設置用戶$client_id
這裏的代碼,我曾嘗試在條件
if($role == 'client'){
$this->AppComment->recursive = 0;
$client_id = $this->Session->read('Client.id');
$this->Paginator->settings = array(
'conditions' => array('AppComment.client_id' => $client_id)
);
$this->set('appComments', $this->Paginator->paginate());
}
我發現錯誤
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in 'where clause'
這裏是
<pre><?php print_r($this->Session->read('Client.id')); ?> </pre>
輸出的輸出我得到
Array
(
[0] => Array
(
[Client] => Array
(
[id] => 1
)
)
)
一切似乎是正確的,我會幫助,如果你提供你的代碼更片斷 –
OK讓我增加更多code.I編輯我的問題。 –
一切看起來都很好。檢查數據來了或不在$ client_id中。 – Shaddy