skip to Main Content

Whenever I try to generate a model using Gii in the Yii framework, it throws:

php warning : count(): Parameter must be an array or an object that implements Countable

It also mentions following file:

appprotectedvendoryiisoftyiiframeworkgiigeneratorsmodelModelCode.php(371)

While questions with same title exists, none of them fixed mine.I’m using yii version 1.1.14 and windows 10

3

Answers


  1. You should upgrade Yii to 1.1.21 – this bug was fixed almost 2 years ago.

    Login or Signup to reply.
  2. Downgrading Php to 5.6 works fine with the older versions of yii.

    Login or Signup to reply.
  3. If you want to fix it without upgrading your existing Yii version, then follow as below.
    Go to

    framework/gii/generators/model/ModelCode.php:371

    and fix with

    $pk=$table->primaryKey;
    $count=is_array($pk) ? count($pk) : 1;
    return ($count === 2 // we want 2 columns
    

    Just check the $pk is an array or not and store value in a new variable $count and return it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search