Php 使用Yii 2.0.6在显示中不显示任何内容
我使用的是YII 2.0.6 basic,三个文件的代码如下:- 模型文件即“UserForm.php”Php 使用Yii 2.0.6在显示中不显示任何内容,php,yii2,Php,Yii2,我使用的是YII 2.0.6 basic,三个文件的代码如下:- 模型文件即“UserForm.php” namespace app\models; use yii\base\Model; class UserForm extends Model { public $name; public $email; public function rules() { return[
namespace app\models;
use yii\base\Model;
class UserForm extends Model
{
public $name;
public $email;
public function rules()
{
return[
[['name','email'],'required'],
['email','email']
];
}
}
控制器文件,即“SiteController.php”
public function actionUser()
{
$model = new UserForm;
if($model->load(Yii::$app->request->post())&& $model->validate())
{
Yii::$app->session->setFlash('success','You have entered the data correctly.');
}
$this->render('user',['model'=>$model]);
第三个视图文件是“user.php”
use yii\helpers\Html;
use yii\widgets\ActiveForm;
if(Yii::$app->session->hasFlash('success'))
{
echo Yii::$app->getFlash('success');
}
$form = ActiveForm::begin()
<? $form->field($model,'name'); ?>
<? $form->form($model,'email'); ?>
<? Html::submitButton('Submit',['class' => 'btn btn-success']); ?>
ActiveForm::end()
使用yii\helpers\Html;
使用yii\widgets\ActiveForm;
如果(Yii::$app->session->hasFlash('success'))
{
echo Yii::$app->getFlash('success');
}
$form=ActiveForm::begin()
ActiveForm::end()
我在浏览器中使用此链接来显示数据。我认为这个链接是正确的
当我转到此链接时,浏览器不会显示任何内容,既不会显示错误,也不会显示任何输出
有谁能帮我一下吗?确切的问题在哪里?
提前感谢。我认为您应该在
操作用户中使用return
这样:
public function actionUser()
{
$model = new UserForm;
if($model->load(Yii::$app->request->post())&& $model->validate())
{
Yii::$app->session->setFlash('success','You have entered the data correctly.');
}
return $this->render('user',['model'=>$model]); // return here
如果这对你有用,谢谢。除了接受答案外,您还可以通过投票向上箭头将其标记为有用。