0
votes

I have created company controller, view and model files using Yii. Everything was working fine but now when I go to create a new company, it is showing me this error:

Fatal error: Class 'Company' not found in E:\projectsroot\@@@YII\admin\protected\controllers\CompanyController.php on line 65**

My controller code is:

    <?
    public function actionCreate()
{
     $model=new Company;

     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);

     if(isset($_POST['Company']))
     {
        $model->attributes=$_POST['Company'];

                    $model->created_at=date('Y-m-d H:i:s');
                    //$model->status='active';

         $images_path = realpath(Yii::app()->basePath . '/../images/logo');
                    $file=CUploadedFile::getInstance($model,'image');
                    if($file){
                        $model->image=date('YmdHis').'.'.$file->extensionName;
                        $file->saveAs($images_path . '/' .$model->image);
                    }
                    else
                    {
                        $model->image='noimage.jpg';
                    }
         if($model->save())
             $this->redirect(array('view','id'=>$model->id));
    }

    $this->render('create',array(
        'model'=>$model,
    ));
}

   ?>

I am getting the error on the line $model = new Company;

Can anyone help me understand the problem?

1
Do you have a model with name in models folder? also check if model name cases matches - hemc4
a hunch tells me you might have short tag problems... - Developerium

1 Answers

0
votes

Just add below namespace

use app\models\Company;

It might work for you.