PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 12, 2022

[FIXED] Yii2: How to load model in component?

 January 12, 2022     php, yii, yii2     No comments   

Issue

I am beginner in Yii2 basic. I have done this code in Yii 1.1. This is working working fine in Yii 1. But unable to load model in yii2.

Please check my code:

components/UserFun.php

<?php
namespace app\components;

use yii\base\Component;
use Yii;
use yii\base\Model;

class UserFun extends Component {
    public function getStudioId($params = '') {
        $studio = Studio::find()->where("id=:id",[':id' => $studio_id]); /* Skipped rest code */
        return $studio->id;
    }
}

Above my code I am getting this error.

PHP Fatal Error – yii\base\ErrorException

Class 'app\components\Studio' not found

Please help me


Solution

you have to include you Studio model first.

like use frontend\models\Studio; or whatever your model namespace is.

In Yii1 it was a different story, because there was no namespaces.



Answered By - ArtOsi
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing