2015-08-21 212 views
0

大家好我目前正在使用zend 2.3。在列出學生的同時,我正在嘗試建立鏈接,以便顯示關於選定人員的詳細信息。我的問題是,我無法將選定的ID傳遞給模塊控制器中的動作。下面是coresponds鏈接我的看法代碼:無法將參數從視圖傳遞到控制器

<a href="<?php echo $this->url('admin' , 
      array('controller'=>'Admin', 'action'=>'viewstudent', 'ID' => $student->ID))."/admin/viewstudent";?>">detales</a> 

和動作控制器

public function viewstudentAction() 
{ 

    $id = (int) $this->params()->fromRoute('ID', 0); 
echo $id; 
//echo var_dump($id); 
    return new ViewModel(array(
     'students' => $this->getStudentTable()->viewstudent($id), 
    )); 
} 

然後我var_dump $id變量它顯示爲0那麼,什麼是做到這一點的正確方法是什麼?

我已經編輯在href的這樣的代碼

<a href="<?php echo $this->url('admin/default' , 
      array('controller'=>'Admin', 'action'=>'viewstudent', 'id' => $student->ID));?>">Просмотр</a> 

,並解析到此:

<a href="/disability/public/admin/Admin/viewstudent">Просмотр</a> 

網址是

http://localhost:8080/disability/public/admin/Admin/viewstudent

URL是

http://localhost:8080/disability/public/admin/Admin/viewstudent

問題是相同的ID沒有通過

+0

你有路由設置的例子向上? 看這個,URL會導致類似於/ Admin/viewstudent/[ID]/admin/viewstudent的東西? – Rachel

+0

@Rachel感謝評論我編輯了一個href部分問題仍然存在。 –

回答

0

我已經找到了解決問題的辦法。我使用的查詢傳遞的參數在這裏是如何看起來在查看文件

<a href="<?php echo $this->url('admin/default', 
    array('controller' => 'Admin', 
      'action'=>'viewstudent' 
    ), 
    array('query' => 
     array('id' => $student->ID) 
    ) 
); 

     ?>">view</a> 

,然後用$這個 - > PARAMS retreave它在我的控制文件

$id = $this->params()->fromQuery('id'); 
相關問題