我試圖定義一個變量,傳遞到控制器的動作如下CakePHP的控制方法變量
public function index($branch = null) {
//padmanabha-nagar
//jp-nagar
$branch = "padmanabha-nagar";
$this->loadModel('Branch');
// Check if the Branch is valid
if(!empty($branch)){
$this->Branch->recursive = -1;
$branch_result = $this->Branch->find('first', array('order' => array('Branch.name ASC'), 'conditions' => array('Branch.slug' => $branch)));
//debug($branch_result);
// Fetch the Branch ID
if(!empty($branch_result)){
$branch_id = $branch_result['Branch']['id'];
} else {
return $this->redirect(array('controller' => 'pages', 'action' => 'home'));
}
// Fetch the Gallery Images
$this->Gallery->recursive = -1;
$this->Paginator->settings = $this->paginate;
$galleries = $this->Gallery->find('all', array('conditions' => array('Gallery.branch_id' => $branch_id)));
//debug($galleries);
}
$this->set(compact('galleries', 'branch_result'));
}
但是,當我嘗試訪問$分支它似乎並沒有被設置。有沒有其他配置需要我這樣做,以便我可以獲取內容?
你的問題有點不清楚。你的問題是'$ branch'沒有從視圖設置到動作?如果是這樣的話,你可以發佈你如何創建網址來調用該動作嗎?如果那不是問題,你能解釋一下嗎? – Nunser 2014-09-29 12:11:08