Con-6ren">
gpt4 book ai didi

php - 如何从 kohana 中的 View 重定向

转载 作者:行者123 更新时间:2023-12-04 21:13:49 26 4
gpt4 key购买 nike

我有一个名为 action_reg_user 的函数,它将数据插入到数据库中。我试着像往常一样:

header('Location:page/param1/param2');

但是没用

<?php

if(!empty($_POST)){
$username = $_POST['uname'];
$pword = md5($_POST['pword']);
print_r($_POST);

?>
<a href="reg_user/<?php echo $username; ?>/<?php echo $pword; ?>">Continue Registration</a>

<?php } ?>

最佳答案

在最终页面准备好返回浏览器之前,Kohana 不会生成请求 header 。如果你查看 application/bootstrap.php,你会在最底部看到这个:

echo Request::instance()
->execute()
->send_headers()
->response;

因此,您要做的是获取 Request 对象并要求它为您执行重定向。通常,这应该在您的 Controller 中完成,而不是您的 View 。在 Controller 中,您可以执行 $this->request->redirect('kohana/path')。如果你坚持在 View 中这样做,你希望 Request::current()->redirect('kohana/path') 重定向层次链中当前正在执行的请求。

小心并注意那些在路径中没有使用 URL::base - Request::redirect 处理它,所以你只需要指定 Controller /操作/参数。

关于php - 如何从 kohana 中的 View 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6053671/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com