2015-08-21 43 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'); 
相关问题