0
votes

I faced this error at the following code and I can't solve it. What should I do? I'm a beginner in Yii2.

Fatal error: Uncaught Error: Class 'yii\widgets\ActiveForm' not found C:\wamp64\www\yii-basic\views\post\index.php

<?php
use yii\widgets\ActiveForm;
use yii\helpers\Html;
?>
<?php
$form = ActiveForm::begin([
'id'=>'post-form',
'options'=>['class'=>'form-horizontal']
]);
?>
<?= $form->field('$model','title');?>
<?= $form->field('$model','content')->textarea();?>
<?= $form->field('$model','tags');?>
<?= $form->field('$model','status')->checkbox();?>

<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
    <?= Html::submitButton('save',['class','btn btn-success']) ?>
</div>
</div>

<?php
ActiveForm::end();
?>
2
yii\widgets\ActiveForm should be in vendor/yiisoft/yii2/widgets/ActiveForm.php. if you don't have this file, then it means that your installation is incomplete. Try delete vendor directory and run composer install again. - rob006

2 Answers

0
votes

You are missing them in your directory.

Your error is on this line:

 use yii\widgets\ActiveForm;

The problem is that there is no file in that directory named ActiveForm.

Since it was a fatal error it stopped processing the code after that line. You will have to check if you have 'yii\helpers\Html' too.

Solution

Check your folders to see if those files are in there. If not then re verify the installation was successful with Yii.

php yii serve

Sources: Yii-Installation PHP-Namespaces

0
votes

As you have mentioned that you found ActiveForm in yii-basic/vendor/yiisoft/yii2-bootstrap/src/ActiveForm Directory, I think you should

Replace

use yii\widgets\ActiveForm;

With

use yii\bootstrap\ActiveForm;

because, you have installed yii2 bootstrap active form.