Yii Framework Forum: Call to undefined method Pages::getPageCount() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Call to undefined method Pages::getPageCount() Rate Topic: -----

#1 User is offline   rojaro 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 06-October 08
  • Location:hamburg.de

Posted 09 October 2008 - 09:37 AM

Hi,

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 -
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,857
  • Joined: 04-October 08
  • Location:DC, USA

Posted 09 October 2008 - 10:02 AM

What is "Pages"? a new class?
0

#3 User is offline   rojaro 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 06-October 08
  • Location:hamburg.de

Posted 09 October 2008 - 12:13 PM

Technically, yes (the ActiveRecord class created by the model command), but i didnt touch it. I just created a new vhost (yii.dev) 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 http://yii.dev/index.php?r=pages 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 -
0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,857
  • Joined: 04-October 08
  • Location:DC, USA

Posted 09 October 2008 - 12:23 PM

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.)
0

#5 User is offline   rojaro 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 06-October 08
  • Location:hamburg.de

Posted 09 October 2008 - 12:46 PM

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

#6 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,857
  • Joined: 04-October 08
  • Location:DC, USA

Posted 09 October 2008 - 12:52 PM

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.
0

#7 User is offline   rojaro 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 06-October 08
  • Location:hamburg.de

Posted 09 October 2008 - 01:48 PM

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 -
0

#8 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,857
  • Joined: 04-October 08
  • Location:DC, USA

Posted 09 October 2008 - 01:54 PM

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?
0

#9 User is offline   rojaro 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 06-October 08
  • Location:hamburg.de

Posted 09 October 2008 - 02:28 PM

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.
0

#10 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,857
  • Joined: 04-October 08
  • Location:DC, USA

Posted 09 October 2008 - 02:30 PM

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.
0

#11 User is offline   rojaro 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 06-October 08
  • Location:hamburg.de

Posted 09 October 2008 - 02:36 PM

But there is no PagesController.php file.
0

#12 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,857
  • Joined: 04-October 08
  • Location:DC, USA

Posted 09 October 2008 - 02:39 PM

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 ?
0

#13 User is offline   rojaro 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 06-October 08
  • Location:hamburg.de

Posted 09 October 2008 - 02:45 PM

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

Attached File(s)


0

#14 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,857
  • Joined: 04-October 08
  • Location:DC, USA

Posted 09 October 2008 - 02:48 PM

and the view file?
0

#15 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,857
  • Joined: 04-October 08
  • Location:DC, USA

Posted 09 October 2008 - 02:52 PM

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.
0

#16 User is offline   rojaro 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 06-October 08
  • Location:hamburg.de

Posted 09 October 2008 - 03:05 PM

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]. ;)
0

#17 User is offline   rojaro 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 29
  • Joined: 06-October 08
  • Location:hamburg.de

Posted 09 October 2008 - 03:32 PM

Works with rev60, thanks for the checkin!
Karma++  ;D
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users