I
I
Ivan Komarov2017-01-18 07:44:40
Yii
Ivan Komarov, 2017-01-18 07:44:40

Yii2: Class 'ActiveForm' not found?

So the problem is this:
There is an action in siteController

public function actionProfile()
    {
        if (Yii::$app->user->isGuest) {
            return $this->goHome();
        }
        $model = new ProfileForm();
        $fields = $model->loadProfileData($language);
        return $this->render('user-profile', array(
            'fields'=>$fields,
            'model'=>$model,
        ));
    }

Everything works great here.
Next, there is an additional controller serving the user profile page, in which there is an action save, which is called via an ajax request (when the save button is clicked) and renders the same view as the action in the siteController.
However, when rendering I get an error Class 'ActiveForm' not found?
Can anyone suggest why this is happening?
Here is the additional controller code:
class ProfileController extends Controller {

 public function actionSave()
    {
         if (Yii::$app->user->isGuest) {
            return $this->goHome();
        }
        $request = Yii::$app->getRequest();
        $model = new ProfileForm();
        if ($request->isPost && $model->load($request->post())) {
            $fields = $model->loadProfileData($language);
            $message = "Your profile data has been saved";
            return $this->render('user-profile', array(
                    'fields' => $fields,
                    'model' => $model,
                    'message' => $message
            ));
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2017-01-18
@masterfreelance

and renders the same view as the action in the siteController.

No, not the same one. The ProfileController renders a view located at @app/views/profile/user-profile.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question