页面上的内部服务器错误,格式为Yii2

时间:2018-07-18 05:48:29

标签: php yii2 yii2-basic-app

嗨,当我将页面托管在实时Web主机上后尝试访问其页面时,收到此错误消息。不幸的是,此错误未出现在我的测试服务器上。托管服务器的PHP版本为7.1.19,并在apache上运行。

    yii\base\ErrorException: An internal server error occurred. in /home/mywebhost/public_html/app/vendor/yiisoft/yii2/base/ErrorHandler.php:317
    Stack trace:
    #0 [internal function]: yii\base\ErrorHandler->handleError(256, 'An internal ser...', '/home/mywebhost/...', 317, Array)
    #1 /home/mywebhost/public_html/app/vendor/yiisoft/yii2/base/ErrorHandler.php(317): trigger_error('An internal ser...', 256)
    #2 /home/mywebhost/public_html/app/vendor/yiisoft/yii2/widgets/ActiveField.php(178): yii\base\ErrorHandler::convertExceptionToError(Object(yii\base\InvalidConfigException))
    #3 /home/mywebhost/public_html/app/views/site/_clients.php(532): yii\widgets\ActiveField->__toString()
    #4 /home/mywebhost/public_html/app/vendor/yiisoft/yii2/base/View.php(336): require('/home/mywebhost/...')
    #5 /home/mywebhost/public_html/app/vendor/yiisoft/yii2/base/View.php(254): yii\base\View->renderPhpFile('/home/mywebhost/...', Array)
    #6 /home/mywebhost/public_html/app/vendor/yiisoft/yii2/base/View.php(156): yii\base\View->renderFile('/home/mywebhost/...', Array, Object(app\controllers\SiteController))
    #7 /home/mywebhost/public_html/app/vendor/yiisoft/yii2/base/Controller.php(384): yii\base\View->render('_clients', Array, Object(app\controllers\SiteController))
    #8 /home/mywebhost/public_html/app/controllers/SiteController.php(72): yii\base\Controller->render('_clients', Array)
    #9 [internal function]: app\controllers\SiteController->actionClientDetails()
    #10 /home/mywebhost/public_html/app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
    #11 /home/mywebhost/public_html/app/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
    #12 /home/mywebhost/public_html/app/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction('client-details', Array)
    #13 /home/mywebhost/public_html/app/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction('site/client-details', Array)
    #14 /home/mywebhost/public_html/app/vendor/yiisoft/yii2/base/Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request))
    #15 /home/mywebhost/public_html/index.php(7): yii\base\Application->run()
    #16 {main}
    2018-07-18 01:00:11 [196.103.192.115][-][mbgo1e37qtc3ilqdu6iivk2kv6][info][application] $_GET = [
        'r' => 'client-details'
    ]

我的活动表格被声明为据说我有问题,其他所有表格也被声明为有问题。具有表单的所有页面也都返回相同的错误。

    <?php  
    use yii\widgets\ActiveForm; 
    ?>
    <?php $form = ActiveForm::begin(['options'=>['name'=>'clients','id'=>'client_details']]); ?>
    <div class="row pb40"> 
        <div class="clients-form  col-sm-12 col-md-12  col-lg-12 col-xs-12 pull-left">
            <div class="col-sm-10 col-md-10  col-lg-10 col-xs-10 pull-left">
                <div class="clearfix"></div>
                <div class="col-sm-6 col-md-6  col-lg-6 col-xs-6 pull-left">
                <?= $form->field($model, 'national_id')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-sm-6 col-md-6  col-lg-6 col-xs-6 pull-right">
                <?= $form->field($model, 'mobile_phone')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="clearfix"></div> 
                <div class="col-sm-6 col-md-6  col-lg-6 col-xs-6 pull-left">
                <?= $form->field($model, 'first_name')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-sm-6 col-md-6  col-lg-6 col-xs-6 pull-right">
                <?= $form->field($model, 'last_name')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="clearfix"></div>  
                <div class="col-sm-6 col-md-6  col-lg-6 col-xs-6 pull-left">
                <?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="col-sm-6 col-md-6  col-lg-6 col-xs-6 pull-right">
                <?= $form->field($model, 'address')->textInput(['maxlength' => true]) ?>
                </div>
                <div class="clearfix"></div> 
                <div class="col-sm-6 col-md-6  col-lg-6 col-xs-6 pull-left">
                <?= $form->field($model, 'country')->dropDownList(\yii\helpers\ArrayHelper::map(\app\modules\config\models\Countries::find()->all(), 'name', 'name'));?>  
                </div>
                <div class="col-sm-6 col-md-6  col-lg-6 col-xs-6 pull-right">
                <?= $form->field($model, 'city')->dropDownList(\yii\helpers\ArrayHelper::map(\app\modules\config\models\Cities::find()->all(), 'name', 'name'));?>  
                </div>   
            </div>
        <div class="col-sm-2 col-md-2  col-lg-2 col-xs-2 pull-right"> 
            <div class="col-sm-6 col-md-6  col-lg-6 col-xs-6 pull-right"> 
                <?= $form->field($model, 'payment_channel')->textInput(['maxlength' => true])->hiddenInput()->label('') ?>  
            </div>  
        </div>
    </div>
    <div class="clearfix"></div> 
    <div id="explantion"></div>  
        </div> 
        <a href="#payment" class="btn btn-dark-main btn-next-tabs pull-right">Next</a>
    <?php $form::end();?>

下面也是创建表单的模型。

    <?php

    use Yii;

    class Clients extends \yii\db\ActiveRecord {

        public static function getDb() {
            return Yii::$app->get('connect1');
        }

        public function rules() {
            return [
                    [['first_name', 'last_name', 'mobile_phone', 'email', 'address', 'country', 'city', 'national_id'], 'required'],
                    [['display_record', 'payment_channel', 'company_id'], 'integer'],
                    [['total_amount'], 'number'],
                    [['created_on', 'updated_on'], 'safe'],
                    [['first_name', 'last_name', 'mobile_phone', 'email'], 'string', 'max' => 128],
                    [['address', 'country', 'city'], 'string', 'max' => 250],
                    [['national_id'], 'string', 'max' => 50],
            ];
        }

        public function attributeLabels() {
            return [
                'id' => Yii::t('app', 'ID'),
                'first_name' => Yii::t('app', 'First Name'),
                'last_name' => Yii::t('app', 'Last Name'),
                'mobile_phone' => Yii::t('app', 'Mobile Phone'),
                'email' => Yii::t('app', 'Email'),
                'address' => Yii::t('app', 'Address'),
                'country' => Yii::t('app', 'Country'),
            ];
        }

        public static function find() {
            return new ClientsQuery(get_called_class());
        }

        public function getName() {
            return $this->first_name . ' ' . $this->last_name;
        }

    } 

下面是我正在使用的控制器

    <?php
    namespace app\controllers; 
    use yii\filters\AccessControl;
    use yii\web\Controller; 
    use yii\filters\VerbFilter;  

    class SiteController extends Controller {

        /**
         * {@inheritdoc}
         */ 
        public $layout = "//Public"; 

        public function behaviors() {
            return [
                'access' => [
                    'class' => AccessControl::className(),
                    'only' => ['logout'],
                    'rules' => [
                        [
                            'actions' => ['logout'],
                            'allow' => true,
                            'roles' => ['*'],
                        ],
                    ],
                ],
                'verbs' => [
                    'class' => VerbFilter::className(),
                    'actions' => [
                        'logout' => ['post'],
                    ],
                ],
            ];
        }

        /**
         * {@inheritdoc}
         */
        public function actions() {
            return [
                'error' => [
                    'class' => 'yii\web\ErrorAction',
                ],
                'captcha' => [
                    'class' => 'yii\captcha\CaptchaAction',
                    'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
                ],
            ];
        }


        /**
         * Displays homepage.
         *
         * @return string
         */
        public function actionIndex()
        { 
            return $this->render('_home_content');
        }

        public function actionClientsDetails()
        { 
            $model =  new \app\models\Clients(); 
            $model->payment_channel = 4; 
            return $this->render('_clients',['model'=> $model]);
        }

        public function actionOurGallery()
        {
            return $this->render('_gallery');
        } 
        /**
         * Displays about page.
         *
         * @return string
         */
        public function actionAbout() {
            return $this->render('about');
        }

    }

2 个答案:

答案 0 :(得分:1)

在聊天中与@robsch进行了大量讨论后,发现问题出在目录'assets'丢失。我创建了文件夹'assets',一切恢复正常。

答案 1 :(得分:0)

当我想使用验证码作为窗口小部件并且验证码操作出错时,我也遇到了这个错误。

main

当我解决了<?php echo $register_form->field($login_model, 'verifyCode')->widget(Captcha::className(), [ 'captchaAction' => '/core/frontend/default/captcha', 'template' => '<div class="row"><div class="col-sm-6">{input}</div><div class="col-sm-6">{image} <a href="javascript:;" id="refresh-captcha"><span class="fa fa-refresh"></span></a></div></div>', 'imageOptions' => [ 'id' => 'my-captcha-image', 'style' => 'height: 35px', ], ]); ?> 路线上的错误时,我的问题就解决了。