Reputation: 11
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();
?>
Upvotes: 0
Views: 1284
Reputation: 1092
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.
Upvotes: 0
Reputation: 497
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
Upvotes: 1