zend paginator 将其他链接和 Action Calling 与 URL 连接起来 [英] zend paginator make other links and Action Calling concatinating with the URL
问题描述
我是 ZF 的新手.我在我的第一个项目中使用了 zend 分页器.它工作正常,可以以正确的结果切换黑白页面,但问题是我在该视图中也有其他链接,请查看我的视图
I am NEW to ZF .i used zend paginator in my first project .its working fine that is switching b/w pages with right result but the problem is that i have other links too in that view have a look to my view
<?php include "header.phtml"; ?>
<h1><?php echo $this->escape($this->title);?></h1>
<h2><?php echo $this->escape($this->description);?></h2>
<a href="register">Register</a>
<table border="1" align="center">
<tr>
<th>User Name</th>
<th>First Name</th>
<th>Last Name</th>
<th>Action</th>
</tr>
<?php
foreach($this->paginator as $record){?>
<tr>
<td><?php echo $record->user_name;?></td>
<td><?php echo $record->first_name;?></td>
<td><?php echo $record->last_name;?></td>
<td>
<a href="edit/id/<?php echo $record->id;?>">Edit</a>
|
<a href="del/id/<?php echo $record->id;?>">Delete</a>
</td>
</tr>
<?php } ?>
</table>
<?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination.phtml'); ?>
<?php include "footer.phtml"; ?>
正如我所说的,分页呈现并且工作正常,但是当我点击这些链接时
as i said the pagination renders and working fine but when i click on these links
<a id="edit_link" href="edit/id/<?php echo $record->id;?>">Edit</a>
or
<a id="delete_link" href="del/id/<?php echo $record->id;?>">Delete</a>
or
<a href="register">Register</a>
它没有调用所需的操作,而是使我的网址像这样
it is not calling the required action instead it make my url like this
(initial link) http://localhost/zend_login/web_root/index.php/task/list
点击以上任何一个链接后都是这样
after clicking any of the above link its like this
http://localhost/zend_login/web_root/index.php/task/list/page/edit/id/8
http://localhost/zend_login/web_root/index.php/task/list/page/edit/id/edit/id/23
http://localhost/zend_login/web_root/index.php/task/list/page/edit/id/edit/id/register http://localhost/zend_login/web_root/index.php/task/list/page/edit/id/edit/id/del/id/12
注意它不会在页面第一次呈现时发生,但是当我点击任何分页链接时,它最初会执行此操作并显示视图......任何帮助都是这里行动
note its not happening when the page renders first time but when i click on any pagination link its doing so initialy its going to the reguired action and displaying a view...any help HERE IS THE ACTION
public function listAction(){
$registry = Zend_Registry::getInstance();
$DB = $registry['DB'];
$sql = "SELECT * FROM task ORDER BY task_name ASC";
$result = $DB->fetchAll($sql);
$page=$this->_getParam('page',1);
$paginator = Zend_Paginator::factory($result);
$paginator->setItemCountPerPage(3);
$paginator->setCurrentPageNumber($page);
$this->view->assign('title','Task List');
$this->view->assign('description','Below, are the Task:');
$this->view->paginator=$paginator;
}
推荐答案
将此添加到您的操作中
$request = $this->getRequest();
$this->view->assign('url', $request->getBaseURL());
并用此替换视图中的链接
and replace your links in view with this
<a href="<?php echo $this->url."/task/register"?>">Add a Task</a>
<a href="<?php echo $this->url.'/task/edit/id/'.$record->id;?>">Edit</a>
<a href="<?php echo $this->url.'/task/del/id/'.$record->id;?>">Delete</a>
这篇关于zend paginator 将其他链接和 Action Calling 与 URL 连接起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!