我正在尝试定义一个将传递给控制器动作的变量,如下所示
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 时,它似乎没有设置。我需要做任何其他配置才能获取内容吗?