2016-05-01 2 views
1

Динамическая форма Yii2, получение ошибки «Не удалось найти« backend \ models \ QuoteDocs »в файле: C: \ xampp \ htdocs \ taskmanagement/backend/models/QuoteDocs.php. Пространство имен отсутствует? "Не удалось найти бэкэнд models пространство имен QuoteDocs отсутствует

, когда я пытаюсь написать бэкэнд \ модели \ QuoteDocs Я получаю следующее сообщение об ошибке

enter image description here

, когда я пытаюсь написать приложение \ модели \ QuoteDocs я получаю следующее сообщение об ошибке

enter image description here

Controller Код:

namespace backend\controllers; 
use Yii; 
use app\models\Quotations; 
use app\models\QuotationsSearch; 
use backend\models\QuoteDocs; 
use yii\web\Controller; 
use yii\web\NotFoundHttpException; 
use yii\filters\VerbFilter; 
use app\models\DocType; 
/** 
* QuotationsController implements the CRUD actions for Quotations model. 
*/ 
class QuotationsController extends Controller 
{ 
    public function behaviors() 
    { 
     return [ 
      'verbs' => [ 
       'class' => VerbFilter::className(), 
       'actions' => [ 
        'delete' => ['post'], 
       ], 
      ], 
     ]; 
    } 

    /** 
    * Lists all Quotations models. 
    * @return mixed 
    */ 
    public function actionIndex() 
    { 
     $searchModel = new QuotationsSearch(); 
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams); 

     return $this->render('index', [ 
      'searchModel' => $searchModel, 
      'dataProvider' => $dataProvider, 
     ]); 
    } 

    /** 
    * Displays a single Quotations model. 
    * @param integer $id 
    * @return mixed 
    */ 
    public function actionView($id) 
    { 
     return $this->render('view', [ 
      'model' => $this->findModel($id), 
     ]); 
    } 

    /** 
    * Creates a new Quotations model. 
    * If creation is successful, the browser will be redirected to the 'view' page. 
    * @return mixed 
    */ 
    public function actionCreate() 
    { 

     $model = new Quotations(); 
     $modelQuoteDocs=[new QuoteDocs]; 

     if ($model->load(Yii::$app->request->post())) { 
     $modelQuoteDocs = Model::createMultiple(QuoteDocs::classname()); 
      Model::loadMultiple($modelQuoteDocs, Yii::$app->request->post()); 


      // validate all models 
      $valid = $model->validate(); 
      $valid = Model::validateMultiple($modelQuoteDocs) && $valid; 

      if ($valid) { 
       $transaction = \Yii::$app->db->beginTransaction(); 
       try { 
        if ($flag = $model->save(false)) { 
         foreach ($modelQuoteDocs as $modelQuoteDoc) { 
          $modelQuoteDoc->qdoc_quotation_id = $model->q_id; 
          if (! ($flag = $modelQuoteDoc->save(false))) { 
           $transaction->rollBack(); 
           break; 
          } 
         } 
        } 
        if ($flag) { 
         $transaction->commit(); 

         if ($model->save(false)) { 
          return $this->redirect(['view', 'id' => $model->q_id]); 
         } 
        } 
       } catch (Exception $e) { 
        $transaction->rollBack(); 
       } 
      } 
     }else { 
      return $this->render('create', [ 
       'model' => $model, 
       'modelQuoteDocs' => (empty($modelQuoteDocs)) ? [new QuoteDocs] : $modelQuoteDocs 
      ]); 
     } 
    } 


    /** 
    * Updates an existing Quotations model. 
    * If update is successful, the browser will be redirected to the 'view' page. 
    * @param integer $id 
    * @return mixed 
    */ 
    public function actionUpdate($id) 
    { 
     $model = $this->findModel($id); 

     if ($model->load(Yii::$app->request->post()) && $model->save()) { 
      return $this->redirect(['view', 'id' => $model->q_id]); 
     } else { 
      return $this->render('update', [ 
       'model' => $model, 
      ]); 
     } 
    } 

    /** 
    * Deletes an existing Quotations model. 
    * If deletion is successful, the browser will be redirected to the 'index' page. 
    * @param integer $id 
    * @return mixed 
    */ 
    public function actionDelete($id) 
    { 
     $this->findModel($id)->delete(); 

     return $this->redirect(['index']); 
    } 

    /** 
    * Finds the Quotations model based on its primary key value. 
    * If the model is not found, a 404 HTTP exception will be thrown. 
    * @param integer $id 
    * @return Quotations the loaded model 
    * @throws NotFoundHttpException if the model cannot be found 
    */ 
    protected function findModel($id) 
    { 
     if (($model = Quotations::findOne($id)) !== null) { 
      return $model; 
     } else { 
      throw new NotFoundHttpException('The requested page does not exist.'); 
     } 
    } 
} 

ответ

0

Кажется, связанные с вами use backend\models\QuoteDocs;

Затем Убедитесь, что вы имеете QuoteDocs модель в серверной модели ..

Может быть, есть ошибка, и модель в приложении

........ 
use app\models\QuoteDocs; 

В противном случае может быть вы не не присваивается правильное пространство имен для

бэкенд \ модели \ QuoteDocs

модель

0

Просто добавьте в контроллер использования раздела

use yii\base\Model; 
Смежные вопросы