Yii Framework Forum: $model - Yii Framework Forum

Jump to content

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

$model Same variable everywhere Rate Topic: -----

#1 User is offline   Backslider 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 363
  • Joined: 23-July 09

Posted 02 August 2009 - 11:37 PM

When I create an application using YIIC, every new file it seems uses the variable $model. This makes reading the code an unhappy task.

While reading the Blog tutorial, it can be seen that a saner variable naming method is used, eg. if I am working with the CommentController and comment class, these use the varible $comment. If I am working with PostController and post class then the variable is $post, if UserController and user class then $user.

Why is this convention not used, when your own tutorial points to this being a far better naming convention? With $model all over the place it is very difficult to keep track of things that would be very simple using unique variable names based on the name of the controller/model.
We were all once expert at....... nothing.

yii-language-behavior

My Blog
0

#2 User is offline   oalexandrino 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 16
  • Joined: 11-June 09

Posted 03 August 2009 - 01:48 PM

i think you're speaking about the generated code by yiic tool.

so, it might be just some a way that the coder did when he/she was creating the script.

it doesn't mean that you don't have to follow a code convention.

you can follow a different and more readble convention just by renaming the variable that will be set via controller.


View PostBackslider, on 02 August 2009 - 11:37 PM, said:

When I create an application using YIIC, every new file it seems uses the variable $model. This makes reading the code an unhappy task.

While reading the Blog tutorial, it can be seen that a saner variable naming method is used, eg. if I am working with the CommentController and comment class, these use the varible $comment. If I am working with PostController and post class then the variable is $post, if UserController and user class then $user.

Why is this convention not used, when your own tutorial points to this being a far better naming convention? With $model all over the place it is very difficult to keep track of things that would be very simple using unique variable names based on the name of the controller/model.

"no one person is smart enough or has enough knowledge to figure out everything without assistance"
0

#3 User is offline   Backslider 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 363
  • Joined: 23-July 09

Posted 03 August 2009 - 07:40 PM

Yes, clearly I am talking about the YIIC tool.

My question is also clearly directed toward the developers ;)
We were all once expert at....... nothing.

yii-language-behavior

My Blog
0

#4 User is offline   qiang 

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

Posted 04 August 2009 - 01:56 PM

The reason for using $model is that it is independent of the model name. As a result, it is more likely that you can "reuse" your views.
1

#5 User is offline   Backslider 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 363
  • Joined: 23-July 09

Posted 04 August 2009 - 07:47 PM

Ok, that makes sense.

Any chance of the blog tutorial being updated accordingly?
We were all once expert at....... nothing.

yii-language-behavior

My Blog
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