如何通过MVC传递POST变量?

编程入门 行业动态 更新时间:2024-10-25 22:34:40
本文介绍了如何通过MVC传递POST变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在遵循 MVC指南了解使用MVC模式创建Web应用程序的基础.

I am following this MVC guide to learn the basics of creating web apps with the MVC pattern.

我已经全部设置好并且可以正常工作,当前系统可以使用这种形式的网址;

I have set it all up and it works fine, currently the system works with urls of this form;

address.co.uk/controller/method/params

address.co.uk/controller/method/params

我了解这是如何工作的,但是在发布数据时这将如何工作?例如一个登录表单,我尝试从控制器访问POST变量,但是怎么都行不通,我猜这是由于.htaccess文件将所有内容发送到index.php吗?

I understand how this can work, however how would this work when posting data? for example a login form, i have tried accessing the POST variables from the controller, how ever this doesn't work, im guessing this is due to the .htaccess file sends everything to the index.php?

更新:

所以我已经创建了这种基本形式;

so i have created this basic form;

<form name="input" action="register/newuser" method="post"> Username: <input type="text" name="user" /> password: <input type="text" name="pass" /> <input type="submit" value="Submit" /> </form>

将数据提交给此控制器方法newuser;

That submits data to this controller methods newuser;

function newuser() { $data['user'] = $_POST["user"]; $data['pass'] = $_POST["pass"]; $this->loadView('view_register_result',$data); }

然后是结果页面;

<body> <h1>Result</h1> im not sure? <br /> user: <?php echo $data['user']; ?> pass: <?php echo $data['pass']; ?> </body>

有什么理由不起作用吗?

Is there any reason why this doesn't work?

推荐答案

$_POST是一个超全局变量,意味着它随处可见.当然,除非您执行实际的POST,否则不会填满它.

$_POST is a superglobal, meaning that it's available everywhere. Of course, it won't be filled unless you do an actual POST.

mod_rewrite仅会重写URL,但不会触摸$_POST,$_SESSION或$_COOKIE.只有$_GET可能会稍作更改,但这超出了您的问题范围.

mod_rewrite in the .htaccess will only rewrite the URL, but it won't touch the $_POST, $_SESSION or $_COOKIE. Only the $_GET might be changed slightly, but that's beyond the scope of your question.

修改 您的问题绝对与$_POST无关.将$data作为参数传递给loadView是将它作为$data添加到模板,还是将它作为两个单独的变量添加:user和pass?在这种情况下,请尝试loadView('..', array('data' => $data))

Edit Your issue is definitely unrelated to the $_POST. Does passing $data as an argument to loadView add it to the template as $data, or does it add it as two separate variables: user and pass? In that case, try loadView('..', array('data' => $data))

更多推荐

如何通过MVC传递POST变量?

本文发布于:2023-10-12 00:14:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483240.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   MVC   POST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!