在Yii2中找不到错误

时间:2015-06-05 09:34:04

标签: php yii2

我是yii2框架的新手。我创建了一个控制器,模型和视图。但我得到未找到错误(404)

我创建了控制器TestController.php,一个视图create.php和一个模型Test.php。我已经尝试在特定控制器中运行我的项目,我得到的时间没有找到错误消息。

这是我的控制器页面

控制器由Controller类扩展。我在控制器页面中使用了警告框,但我没有收到任何警报。

class TestController extends Controller
{ 
namespace livefactory\modules\test\controllers;

public function actionCreate()

    {
        if(!Yii::$app->user->can('Test.Create')){
            throw new NotFoundHttpException('You dont have permissions to view this page.');
        }
        $img = new ImageUpload();
        $emailObj = new SendEmail;
        $model = new Test;

            return $this->render('create', [

                'model' => $model,

            ]);

    }
}

我的模型页面

模型页面定义了特定控制器中使用的所有变量。 表名也是定义的。

 namespace livefactory\models;
 class Test extends \yii\db\ActiveRecord
 {
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'tbl_test';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['Name', 'Relationship', 'Age', 'Mail', 'Status'], 'required'],
            [['Age'], 'integer'],
            [['Name', 'Relationship', 'Mail', 'Status'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'Name' => Yii::t('app', 'Person Name'),
            'Relationship' => Yii::t('app', 'Relationship'),
            'Age' => Yii::t('app', 'Age'),
            'Mail' => Yii::t('app', 'Mail'),
            'Status' => Yii::t('app', 'Status'),
    }
}

我的观看页面

<?php



use yii\helpers\Html;

use yii\helpers\Html;

use yii\helpers\ArrayHelper;

use kartik\widgets\ActiveForm;

use kartik\builder\Form;

use livefactory\models\Country;
use livefactory\models\State;
use livefactory\models\City;
use kartik\widgets\DepDrop;

use kartik\datecontrol\DateControl;

use livefactory\models\CustomerType;

/**

 * @var yii\web\View $this

 * @var common\models\Customer $model

 */



$this->title = Yii::t('app', 'Add Person', [

    'modelClass' => 'Test',

]);

// $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Customers'), 'url' => ['index']];

// $this->params['breadcrumbs'][] = $this->title;

?>




                <div class="ibox float-e-margins">

                    <div class="ibox-title">

                        <h5><?= Html::encode($this->title) ?> <small class="m-l-sm"><?php echo Yii::t ( 'app', 'Enter Person Details' ); ?></small></h5>

                        <div class="ibox-tools">

                            <a class="collapse-link">

                                <i class="fa fa-chevron-up"></i>

                            </a>

                            <a class="close-link">

                                <i class="fa fa-times"></i>

                            </a>

                        </div>

                    </div>

                    <div class="ibox-content">

                                         <div class="customer-form">

    <?php



                $form = ActiveForm::begin ( [ 

                        'type' => ActiveForm::TYPE_VERTICAL 

                ] );?>

                <div class="panel panel-info">
                <div class="panel-heading">
                    <h3 class="panel-title"><?php echo Yii::t ( 'app', 'Person Details' ); ?></h3>
                </div>
                <div class="panel-body">
            <?php
                echo Form::widget ( [ 
                        'model' => $model,

                        'form' => $form,

                        'columns' => 4,

                        'attributes' => [ 

                                'Person Name' => [ 

                                        'type' => Form::INPUT_TEXT,

                                        'options' => [ 

                                                'placeholder' => Yii::t ( 'app', 'Enter Person Name' ).'...',

                                                'maxlength' => 255 

                                        ],

                                        'columnOptions' => [ 

                                                'colspan' => 3 

                                        ] 

                                ]
                                ,

                                'Relationship' => [ 

                                        'type' => Form::INPUT_TEXT,

                                        'options' => [ 

                                                'placeholder' => Yii::t ( 'app', 'Enter Relationship' ).'...',

                                                'maxlength' => 255 

                                        ],

                                        'columnOptions' => [ 

                                                'colspan' => 3 

                                        ] 

                                ]

                        ] 

                ]

                 );

                echo Form::widget ( [ 

                        'model' => $model,

                        'form' => $form,

                        'columns' => 3,

                        'attributes' => [ 

                                'Age' => [ 

                                        'type' => Form::INPUT_TEXT,

                                        'options' => [ 

                                                'placeholder' => Yii::t ( 'app', 'Enter Age' ).'...',

                                                'maxlength' => 255 

                                        ] 

                                ],

                                'Mail' => [ 

                                        'type' => Form::INPUT_TEXT,

                                        'options' => [ 

                                                'placeholder' => Yii::t ( 'app', 'Enter Mail' ).'...',

                                                'maxlength' => 255 

                                        ] 

                                ],

                                'Status' => [ 

                                        'type' => Form::INPUT_TEXT,

                                        'options' => [ 

                                                'placeholder' => Yii::t ( 'app', 'Enter Status' ).'...',

                                                'maxlength' => 255 

                                        ] 

                                ] 

                        ] 

                ] );


                ?>
                </div></div>

                <?php

                // echo Html::submitButton ( $model->isNewRecord ? Yii::t ( 'app', 'Create' ) : Yii::t ( 'app', 'Update' ), [ 

                        // 'class' => $model->isNewRecord ? 'btn btn-success customer_submit' : 'btn btn-primary customer_submit' 

                // ] );

                ActiveForm::end ();

                ?>

</div>

                    </div>

                </div>

0 个答案:

没有答案