Kohana排序过滤器实现

发布于 2024-10-20 08:37:23 字数 836 浏览 1 评论 0原文

我正在尝试为虚拟商店实现 kohana 排序过滤器,这意味着每当我想要对某些产品(价格之后等)进行排序时,我必须只从列表中选择排序标准。我不想在另一个视图中实现排序,这样当一个人选择排序选项时,他就不能被重定向到另一个页面。

所以我有一个列表:

<form name="ordering" id="ordering" method="post" action="">
<input type="hidden" id="ordering" value="0">  
<select id="ordering" name="ordering">   
<option value=0>All products</option>
<option value=1>Ascending Price</option>
<option value=2>Descending price</option>


</select>
</form>

然后我想在控制器中获取该隐藏值,以便能够在视图中操作它。 (正确吗?) 我需要这个变量以便能够进行切换并确定用户选择了哪个排序选项。

在控制器中,我尝试使用 $ordering = $_POST['ordering']; 来“捕获”变量但我收到一个错误,或者有一个错误

 if (Request::$is_post){    
    $ordering = $_POST['ordering'];         
    }

,但它永远不会到达那里(在那一堆代码中)。

我哪里错了?

谢谢你!

i am trying to implement a kohana sorting filter for a virtual store, meaning that whenever i want to sort some products (after price, etc)i must only select the sorting criteria from a list. i dont want to implement the sorting in another view, so that when one chooses a sort option, he must not be redirected in another page.

so i have a list:

<form name="ordering" id="ordering" method="post" action="">
<input type="hidden" id="ordering" value="0">  
<select id="ordering" name="ordering">   
<option value=0>All products</option>
<option value=1>Ascending Price</option>
<option value=2>Descending price</option>


</select>
</form>

i want then to take that hidden value in the controller, for being able to manipulate it in the view. (is it correct?)
i need this variable in order to be able to make a switch and to determine which sorting option has been choosen by a user.

in the controller, i try to 'catch' the variable with a $ordering = $_POST['ordering']; but i receive an error, or with a

 if (Request::$is_post){    
    $ordering = $_POST['ordering'];         
    }

but it never gets there (at that bunch of code).

where i am wrong?

thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

丿*梦醉红颜 2024-10-27 08:37:23

给定Request对象的文档和< a href="http://kohanaframework.org/3.0/guide/kohana/routing#request-parameters" rel="nofollow">这个示例,您可以在控制器中尝试以下操作:

if (Request::$method == 'POST') {    
    $ordering = $_POST['ordering'];
    // ...
}

注意:建议在 HTML 标签参数周围加上引号

<option value="0">All products</option>

而不是

<option value=0>All products</option>

HTH

Given the documentation of Request object and this example, you could try the following in your controller :

if (Request::$method == 'POST') {    
    $ordering = $_POST['ordering'];
    // ...
}

Note: it's recommended to put quotes around HTML tag parameters

<option value="0">All products</option>

instead of

<option value=0>All products</option>

HTH

﹏半生如梦愿梦如真 2024-10-27 08:37:23

@dana:看看 - http://www.ajaxlines.com/ ajax/stuff/article/jquery_and_kohana_unobtrusive_ajax.php - 有关如何在用户提交表单时不刷新页面的情况下执行您希望的操作的示例和一些说明。

@dana: Have a look at -- http://www.ajaxlines.com/ajax/stuff/article/jquery_and_kohana_unobtrusive_ajax.php -- for an example and some direction on how to do what you wish to without having the page refresh when a user submits the form.

瀞厅☆埖开 2024-10-27 08:37:23

首先,检查您的 HTML 代码,您有 3 个名为“ordering”的 ID。
我不知道你是如何编写 Javascript 的东西,但如果这不起作用我不会感到惊讶,ID 应该是唯一的。

不管怎样,你说你想获取隐藏字段的值,但它没有任何名称。因此,您无法通过 PHP 访问它(除非您使用 Javascript 进行访问)

根据 Kohana 3.1(最后一条评论链接了 3.0 文档),要获取该值,您应该执行以下操作:

$this->request->post('ordering');

您正在使用什么版本的 Kohana和 ?

First, check your HTML code, you have 3 IDs named "ordering".
I don't know how you wrote your Javascript stuff, but I wouldn't be surprised if that doesn't work, IDs should be unique.

Anyway, you say you want to get the value of the hidden field, but it doesn't have any name. So you can't access to it via PHP (unless you do it with Javascript)

According to Kohana 3.1 (the last comment was linking the 3.0 documentation), to get the value you should do the following:

$this->request->post('ordering');

What version of Kohana are you working with ?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文