2

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:

app\protected\vendor\yiisoft\yii\framework\gii\generators\model\ModelCode.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 Answers3

3

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

rob006
  • 21,383
  • 5
  • 53
  • 74
  • I have to use Yii 1.1.14 as I need to contribute a existing project written with version 1.1.14 – Pasindu Mihirantha Sep 10 '19 at 09:57
  • `1.1.21` is patch release for `1.1.14`, it should be relatively safe to upgrade (see https://github.com/yiisoft/yii/blob/master/UPGRADE for details). Yii 1.1.14 is 6 years old, it has know security issues and it is incompatible with last PHP version - you **should** upgrade anyway, using this version on production is unsafe. – rob006 Sep 10 '19 at 12:11
  • Also you can downgrade your PHP to 7.1 or older (not recommended) – Michael Krutikov Sep 17 '19 at 11:11
-1

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.

Omar
  • 901
  • 11
  • 14
-2

Downgrading Php to 5.6 works fine with the older versions of yii.