我试图定义一个变量,传递到控制器的动作如下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