未知水域钓鱼,我给了klein.php路由旋转,我一生都无法找出如何将 $_POST 从 html 表单传递到另一个 View 。
示例:
index.php
<?php
//START ROUTING
require 'klein.php';
require 'autoload.php';
respond('/', function ($request, $response) {
$response->render('homepage.php', array(
'meta_title' => 'My Homepage'
));
});
respond('/[:name]', function ($request, $response) {
$response->render('siteinfo.php', array(
'meta_title' => 'My Details Page'
));
});
现在,我在 homepage.php 上有一个表单,我可以在其中执行以下操作:
<form method="post">
<input type="text" name="url">
<button type="submit">Submit</button>
</form>
siteinfo.php 获取 url 之后传递的所有内容(即 example.com/product123 -> Product123),并在 View “siteinfo.php”中显示有关该信息的信息。到目前为止,如果手动输入地址栏,这与上面的代码完美配合,因为我可以在 siteinfo.php 上以 $request->name 的形式访问 [:name]。
每当我在表单上触发搜索时,我都想将 $_POST 从 homepage.php View 传递到 index.php 作为 [:name] 而无需 $_GET!知道这如何与 klein.php 一起使用或者我应该从哪里开始寻找答案吗?
我也尝试过传递 param() 值,但这仍然不适用于表单。我也尝试添加 action=index.php/siteinfo.php/homepage.php 作为表单的操作,但仍然不喜欢...
非常感谢任何帮助...
最佳答案
这将是一个很好的起点。到目前为止您尝试过什么?
respond('POST', '/', function ($request, $response) {
$request->validate('url')->notNull();
$response->url= $request->url;
$response->render('homepage.php');
});
关于php - $_POST 与 klein.php 路由器 : How to pass $_POST to a view?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16146150/