I’ve been doing the SYMFONY jobeet tuto(day 10) and once in the FORMS section, I found that some times we use :
'category_id' => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('JobeetCategory'), 'add_empty' => false)),
and sometimes we use simply
'jobeet_affiliates_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'JobeetAffiliate')),
Can anyboody explain to me WHY? and HOW is it working ?
why ,sometimes,do we use getRelatedModelName?? and why somtimes ‘model’ => ‘myModel’???
Pretty much same thing, but, you can only use
getRelatedModelNamewhen there’s a relation between the current form’s model and the model you need in your widget. For example, if there’s a relation defined between Article and Category, you can usegetRelatedModelName('Category')in ArticleForm (usually a relation is defined).In both cases (when a relation exists/does not exist) you can just write the model as a string
'model' => 'JobeetAffiliate'. I usually do that.