Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better name for "Model::formName()" #284

Closed
klimov-paul opened this issue May 15, 2013 · 17 comments
Closed

Better name for "Model::formName()" #284

klimov-paul opened this issue May 15, 2013 · 17 comments

Comments

@klimov-paul
Copy link
Member

Forked from #236

Method name “yii\base\Model::getFormName()” sounds confusing. For me words “form name” associates with “<form name=”form-name”>”.
I suppose this method should be named otherwise, like:

  • getInputName()
  • getInputGroupName()
  • getRequestName()
@nsanden
Copy link
Contributor

nsanden commented May 15, 2013

Agree and I think I like getInputName() best

@qiangxue
Copy link
Member

I think formName is fine. It means this is the name used by the model in a form.

  • getInputName(): this gives the impression of the name of a single input field, which is not the case here.
  • getInputGroupName(): this introduces a new term "group" which isn't well defined.
  • getRequestName(): this is not better than formName. It is actually worse because the term "request" is too generic, while "form" is very specific.

@rawtaz
Copy link
Contributor

rawtaz commented May 15, 2013

If I may chime in, I don't think that a model class (being an entity, normally) should be aware of the surrounding context/environment. It shouldn't know about things like HTML forms, it should be neutral to such things. Having the model class generate a name for the outside context, instead of having some utility/whatever do it, is like doing the reverse of DI, not clean. In Yii 1.1 terms I think the method at hand would belong in CActiveForm. Not sure what that translates to in Yii 2 terms, but preferrably not the model class :)

@rawtaz
Copy link
Contributor

rawtaz commented May 15, 2013

I think I missed the point of the actual discussion. I agree with @klimov-paul that the method should at least be named so that it isn't form specific. A name that indicates it returns some kind of "system" name would be appropriate, like there are in CHtml today.

@klimov-paul
Copy link
Member Author

Possible variations:

  • modelName()
  • dataName()

@mdomba
Copy link
Member

mdomba commented May 15, 2013

modelId() ?

@klimov-paul
Copy link
Member Author

modelId() ?

Sounds to return value, which is unique for each class instance.

@nsanden
Copy link
Contributor

nsanden commented May 15, 2013

rawtaz has good point, i like modelName()

@rawtaz
Copy link
Contributor

rawtaz commented May 15, 2013

If this was to be put in another class (equivalent to CActiveForm or whatever), there wouldn't be a problem coming up with a good name. The fact that this is the case now say something :-)

@klimov-paul
Copy link
Member Author

@rawtaz, see #236

@rawtaz
Copy link
Contributor

rawtaz commented May 15, 2013

Yeah. I don't agree with it.

@mdomba
Copy link
Member

mdomba commented May 15, 2013

Sounds to return value, which is unique for each class instance.

you mean each instance of the same class? why would it mean that? it returns a unique ID of a specific class, there are no two different class with same Id (name)... $model->id() or $model->getId(), $model->getModelId() variations are used in Yii frequently

@klimov-paul
Copy link
Member Author

@mdomba, after some thought, I have nothing against "modelId()". It could be used.

@creocoder
Copy link
Contributor

I think formName() is good. Model::formName() associates with model name inside form. All fine here. No need to rename.

@Ragazzo
Copy link
Contributor

Ragazzo commented May 15, 2013

i also think formName() is good in this case.

@qiangxue
Copy link
Member

Note that "form" doesn't necessarily refer to HTML forms. The term can be used in API as well. It is usually connected with user inputs, regardless of how it is presented.

@klimov-paul
Copy link
Member Author

Resolution: no further actions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants