Call to undefined method Pages::getPageCount()


following Situation:

  • existing table 'Pages' contains 44 records

  • model/crud generated with yiic

  • opened the generated view and received the following Error Message:

[tt]Fatal error: Call to undefined method Pages::getPageCount() in /(…)/yii/framework/web/widgets/pagers/CBasePager.php on line 97[/tt]

Greetings from Hamburg / Germany

  • rojaro -

What is "Pages"? a new class?

Technically, yes (the ActiveRecord class created by the model command), but i didnt touch it. I just created a new vhost ( on my webserver and ran the following commands:

  • [tt]# yicc webapp htdocs[/tt]
  • [tt]# vi htdocs/protected/config/main.php[/tt] (configured my mysql db here with proper dsn and credentials)
  • [tt]# yiic shell htdocs/index.php[/tt]
  • [tt]>> model Pages[/tt] (Pages is an existing innodb table with 44 records in it)
  • [tt]>> crud Pages[/tt]
  • opened with firefox and then, at the end of the page (where it tries to create the pager for the table) received the following message:

    [tt]Fatal error: Call to undefined method Pages::getPageCount() in /var/www/localhost/library/yii/framework/web/widgets/pagers/CBasePager.php on line 97[/tt]

Greetings from Hamburg / Germany

  • rojaro -

That's because of the naming conflict between your Pages and the $pages variable in the generated code. Check actionList in the controller to verify this.

I suggest you use a different AR class name (your AR class name doesn't need to be the same as the table name.)

That's not good. A naming conflict should not arise at this level and this is also bad for naming consistence :frowning:

Unless you are willing to take some strange variable namings, there is always possibility that you hit such kind of naming conflicts.

Of course, yiic could do better to give a warning when such conflict would occur.

So i cant have a url like http://domain.tld/pages/ where a customer, e.g. a book author, might want to publish a few excerpts from a new book or a design company that wants to show a few of the web pages they made?

What other names can't be used?

Greetings from Hamburg / Germany

  • rojaro -

of course you can.

You just need to change the code generated by yiic. Could you upload your PagesController and pages view for me to take a look?

I didnt create any. Like i already wrote in my second post in this thread, i just created the crud stuff via yiic command and tried to access the automatically rendered page. I see the page, with table contents and everything and where it tries to render the pager for the table it produces said message.

I know you didn't change anything.

I just want to see the generated code.

Note, yiic crud is not meant to completely replace your programming task. Its main purpose is to give you a good start. You still need to modify the code if needed.

But there is no PagesController.php file.

No? Did you run "crud Pages"? Then it should create PagesController.php under /protected/controllers for you. Otherwise how can you access /index.php?r=pages ?

Oops - “found” the PagesController after i re-ran crud Pages. Problem remains  ;D

and the view file?

Ok, the view file has problem.

$pages was used in the foreach loop, and it is then passed to the pager at the end. This is not right, because $pages is supposed to be passed from the controller. That's the name conflict I mentioned earlier.

So to solve this, just rename the temp variable $pages in foreach to something else.

Ah i see. Thats an easy to fix once and for all: In framework/cli/views/shell/crud/list.php just replace all occurances of [tt]${$modelVar}[/tt] with [tt]$_{$modelVar}[/tt]. ;)

Works with rev60, thanks for the checkin!

Karma++  ;D