doutao5419 2015-06-05 09:34
浏览 94

在Yii2中找不到错误

I am new to yii2 framework. I have created a controller,model and view. But i am getting not found error(404).

I have create the controller TestController.php, a view create.php and a model Test.php. I have try to run my project in particular controller that time im getting not found error message.

This is my controller page

The controller extends by Controller class. I've using alert boxes in controller page but i hasn't get in any alert.

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,

            ]);

    }
}

My model page

The model page defines all the variables used in the particular controller. The table name is also defined.

 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'),
    }
}

My view page

<?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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 乘性高斯噪声在深度学习网络中的应用
    • ¥15 运筹学排序问题中的在线排序
    • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥30 python代码,帮调试,帮帮忙吧