Unable to find 'app\models\EntryForm'


Hi Friends, I am new to YII-2 an facing following issue:

Unknown Class – yii\base\UnknownClassException

Unable to find ‘app\models\EntryForm’ in file: C:\basic/models/EntryForm.php. Namespace missing?

Please help.

Best Regards,

My codes is here. My project folder id c:\basic and I have installed YII2 with composer.


 public function actionIndex()
         $model = new EntryForm();
         return $this->render('vwUsers', ['model' => $model]);
namespace app\models;

//use Yii;
use yii\base\Model;
class EntryForm extends Model
    public $name;
    public $email;

    public function rules()
        return [
            [['name', 'email'], 'required'],
            ['email', 'email'],
use yii\helpers\Html;
use yii\widgets\ActiveForm; 
use app\models;

<?php $form= ActiveForm::begin();

<?= $form->field($model,'name'); ?>
<?= $form->field($model,'email'); ?>

<?=Html::submitButton('Submit',['class'=>'btn btn-success']);?>
<?php ActiveForm::end();?>

Hi @Shahidma, welcome to the forum.

Where did you put your EntryForm.php file?
It should be located in C:\basic\models directory, or you have to declare the namespace of it accordingly.

Thanks a lot dear. It is in the same directory you mentioned i.e. C:\basic\models. Please see following lines of sitecontroller.php which is a cross check also;

use app\models\LoginForm;
use app\models\ContactForm;
use app\models\EntryForm;

The other two forms are working fine from navbar.

I see.

This error message says that C:\basic\models\EntryForm.php does exists, but it doesn’t have app\models\EntryForm in it.
Please double check the content of EntryForm.php file. And, I’m not sure, but it might be an encoding issue of the file.

namespace app\models;

//use Yii;

Adding the word php to top line <? tag worked. now it reads as <?php.

Thanks a lot and warm regards,

1 Like