yii2: Call to undefined method yii\web\View::findByCondition()

Shows the following error:

PHP Fatal Error – yii\base\ErrorException

Call to undefined method yii\web\View::findByCondition()

in /vendor/yiisoft/yii2/db/BaseActiveRecord.php and shows this part of the file:

private $_related = [];


    /**
     * @inheritdoc
     * @return static|null ActiveRecord instance matching the condition, or `null` if nothing matches.
     */
    public static function findOne($condition)
    {
        return static::findByCondition($condition)->one();
    }

    /**
     * @inheritdoc
     * @return static[] an array of ActiveRecord instances, or an empty array if nothing matches.
     */
    public static function findAll($condition)
    {
        return static::findByCondition($condition)->all();

This is where error comes from. File: LoanStatus.php

<?php
namespace frontend\models;

use Yii;
use yii\base\NotSupportedException;
use yii\db\ActiveRecord;
use common\models\User;
use frontend\models\Loan;

// Loan model class
class LoanStatus extends ActiveRecord {

    public static function tableName() {
        return 'loan_status';
    }

    public static function getLoaner($loanId) {
        $loan = self::findOne(['loan_id' => $loanId]);

        return User::findOne($loan->user_id_loaner);
    }

I call function getLoaner() from LoanStatus, LoanStatus::getLoaner($loanid) in the view file. After refreshing the page I receive the error about, which is written in the name of this issue request.

Table loan_status has the following structure loan_status table structure

And the problem is that I cannot fix this issue for some reason and I do not know what causing this problem.

Thanks in advance.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (9 by maintainers)

Most upvoted comments

@bologer I’ve removed some sensitive data from your var_dump output.