【发布时间】:2017-04-29 14:04:30
【问题描述】:
我已经在现有的 web 应用程序中上传了一个新表单,该应用程序是实时的(Linux 服务器)。但我无法正确设置路线并出现错误。
文件: 1. view/newform/(create,index,view,_view,_form).php
控制器/NewFormController.php
models/NewForm.php
main.php:
'urlManager' => array(
'showScriptName' => false,
'urlFormat' => 'path',
'rules' => array(
'/' => 'site/index',
'newform' => 'newform/create', /*This rule is for new form */
**********************************
我用来在线访问网页的链接:
websitename.com/newform/create or create.php (I get 404 not found)
websitename.com/NewForm/create or create.php (NewFormController cannot find the requested view "create" error )
我可以在 localhost(windows) 上正确查看它 => localhost/public_html/index.php?r=newform/create
问题: 我应该使用什么链接在线查看? 如何获得正确的路线到我创建的表格?
编辑: 在 actionIndex() 中添加路径(/newform/index)后,我可以查看索引页面。控制器
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('NewForm');
$this->render('/newform/index',array(
'dataProvider'=>$dataProvider,
));
}
这里是创建函数:
当我使用它时,我得到错误:找不到请求的视图“_form”
public function actionCreate()
{
$model=new NewForm;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['NewForm']))
{
$model->attributes=$_POST['NewForm'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
$this->render('/newform/create',array(
'model'=>$model,
));
}
【问题讨论】:
-
你使用的是 Yii1 还是 Yii2 ?
-
我正在使用 Yii 1
-
在我看来,你应该使用 $this->render('create',array( 'model'=>$model, ));
标签: php model-view-controller yii