Php 未渲染Yii2视图。返回主视图
因此,我尝试制作一个简单的登记表,同时遵循以下具体指南: 我的问题是,我尝试进行的任何重定向都无法按预期的方式工作 例如,如果我需要移动到gii,我的URL必须是:Php 未渲染Yii2视图。返回主视图,php,mysql,yii2,Php,Mysql,Yii2,因此,我尝试制作一个简单的登记表,同时遵循以下具体指南: 我的问题是,我尝试进行的任何重定向都无法按预期的方式工作 例如,如果我需要移动到gii,我的URL必须是: > http://localhost:8080/index.php?r=gii%2Fdefault%2Findex 而不是 > http://localhost:8080/gii 我正在使用OSX Big-Sur和MAMP。也许我需要配置一些不同的东西 当我尝试访问注册时,我在终端上的日志: > [Wed De
> http://localhost:8080/index.php?r=gii%2Fdefault%2Findex
而不是
> http://localhost:8080/gii
我正在使用OSX Big-Sur和MAMP。也许我需要配置一些不同的东西
当我尝试访问注册时,我在终端上的日志:
> [Wed Dec 9 13:33:22 2020] [::1]:51857 [200]: /signup
[Wed Dec 9 13:33:22 2020] [::1]:51858 [200]: /assets/c2edef5c/jquery.js
[Wed Dec 9 13:33:22 2020] [::1]:51859 [200]: /assets/1e2a1c44/yii.js
[Wed Dec 9 13:33:22 2020] [::1]:51860 [200]: /assets/a6d39922/js/bootstrap.js
[Wed Dec 9 13:33:22 2020] [::1]:51861 [200]: /assets/a6d39922/css/bootstrap.css
[Wed Dec 9 13:33:22 2020] [::1]:51862 [200]: /css/site.css
[Wed Dec 9 13:33:22 2020] [::1]:51863 [200]: /index.php?r=debug%2Fdefault%2Ftoolbar&tag=5fd0b60224015
当我在Windows 10上的XAMPP上执行相同操作时:
> Quit the server with CTRL-C or COMMAND-C.
[Wed Dec 9 13:33:59 2020] PHP 7.4.9 Development Server (http://localhost:8080) started
[Wed Dec 9 13:34:07 2020] [::1]:63263 Accepted
[Wed Dec 9 13:34:07 2020] [::1]:63263 [200]: GET /signup
[Wed Dec 9 13:34:07 2020] [::1]:63263 Closing
[Wed Dec 9 13:34:07 2020] [::1]:63264 Accepted
[Wed Dec 9 13:34:07 2020] [::1]:63265 Accepted
[Wed Dec 9 13:34:07 2020] [::1]:63264 [200]: GET /assets/1f96f9b3/jquery.js
[Wed Dec 9 13:34:07 2020] [::1]:63266 Accepted
[Wed Dec 9 13:34:07 2020] [::1]:63265 [200]: GET /assets/87550bf1/yii.js
[Wed Dec 9 13:34:07 2020] [::1]:63267 Accepted
[Wed Dec 9 13:34:07 2020] [::1]:63266 [200]: GET /assets/cb962770/js/bootstrap.js
[Wed Dec 9 13:34:07 2020] [::1]:63268 Accepted
[Wed Dec 9 13:34:07 2020] [::1]:63267 [200]: GET /assets/cb962770/css/bootstrap.css
[Wed Dec 9 13:34:07 2020] [::1]:63268 [200]: GET /css/site.css
[Wed Dec 9 13:34:07 2020] [::1]:63265 Closing
[Wed Dec 9 13:34:07 2020] [::1]:63264 Closing
[Wed Dec 9 13:34:07 2020] [::1]:63266 Closing
[Wed Dec 9 13:34:07 2020] [::1]:63267 Closing
[Wed Dec 9 13:34:07 2020] [::1]:63268 Closing
[Wed Dec 9 13:34:07 2020] [::1]:63269 Accepted
[Wed Dec 9 13:34:07 2020] [::1]:63269 [200]: GET /index.php?r=debug%2Fdefault%2Ftoolbar&tag=5fd0b62fa5773
[Wed Dec 9 13:34:07 2020] [::1]:63269 Closing
[Wed Dec 9 13:34:07 2020] [::1]:63270 Accepted
[Wed Dec 9 13:34:07 2020] [::1]:63270 Closed without sending a request; it was probably just an unused speculative preconnection
[Wed Dec 9 13:34:07 2020] [::1]:63270 Closing
我的实际脚本(如视频中的脚本):
要使用“漂亮”URL,您应该配置组件urlManager
config,只需在配置文件中搜索它(config/web.php
on yii2 basic)
您的配置应该如下所示:
'urlManager'=>[
'class'=>'yii\web\UrlManager',
'enablePrettyUrl'=>true,//这必须是true
'showScriptName'=>false,
“规则”=>[
],
],
此外,您需要让舒尔确保您的应用服务器(Apache)能够处理这些请求
阅读Yii2官方文件的更多信息:@bpanatta是正确的
名称错误。您能告诉我您的
urlManager
它被禁用了吗。如果我启用它并尝试访问localhost:8080/signup,它仍然会给我一个404错误,正如我看到的,当有类型为POST和model的请求signup()工作时(返回trueish值),您重定向到home url->so可能作为intendet工作,这确实解决了我的问题。添加>'class'=>'yii\web\UrlManager'。然而,我的注册页面仍然不起作用。我的路线有问题吗?你写动作名称的方式!试着从actionSignUp改为actionSignUp,不要大写“U”。Yii2解析器理解,要访问此操作,您应该调用/注册,而不是/signup
public function actionSignUp()
{
$model = new SignupForm();
//POST DATA
//PUT INSIDE THE MODEL BASED ON THE RULES OF THE SIGNUP FORM
if($model->load(Yii::$app->request->post()) && $model->signup()){
return $this->redirect(Yii::$app->homeUrl) ;
}
return $this->render('signup', [
'model' => $model
]);
}