php - 类中 HttpPost 的 PHP 等效项
问题描述
我已经搜索了一段时间,但没有找到太多信息。我在 PHP 项目中使用 MVC 设计,我想将逻辑排除在我的视图之外,所以我一直在尝试看看我是否可以做到这一点......
在 C#/ASP.NET MVC 中,您可以使用如下所示的内容:
public void MyClass {
[HttpPost]
public IActionResult Index(string firstName)
{
return Content($"Hello {firstName}");
}
}
这使得表单在您需要的任何类中发布属性。
我想知道在 PHP 中有没有办法做到这一点,你可以在类内有 Post 请求?也许是这样的?
class MyClass {
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Do your thing here
}
}
解决方案
你有没有尝试过,
respond('POST', '/', function ($request, $response)
{
$request->validate('url')->notNull();
$response->url= $request->url;
$response->render('any page');
});
推荐阅读
- python - 如果我移动依赖项,Pyinstaller 可执行文件将不起作用
- emacs - Emacs, clojure, cider-jack-in
- python - ValueError: bad input shape (560, 5) sklearn
- ios - 在 UIIMageView 中加载或切换相机时图像 (UIImage) 方向发生变化
- javascript - Spotify API 有时有效,有时返回 400: Bad Request 错误
- database - 从这个 oracle 查询返回一个多月
- java - 我可以使用在 javax.validation.constraints.Max 中的 application.yml 中定义的自动装配变量吗?
- python - 为什么量化的 TensorFlow Lite 模型在延迟方面表现不佳?
- java - 具有大小、最小值和最大值的随机数组
- c - 每个向量的乘法矩阵