Jan 7, 2011
In my CakePHP 1.3 application, I need a form control that is: Comprised of multiple form elements, and Reusable in more than one form. I'd like to avoid code duplication if I can. So, I'm creating an element that outputs my form control, and have hit a roadblock when it comes to populating the control with values on an edit action. Now, when you're using the default field types, CakePHP does this for you, but I need to get information out of $this->data and do it myself in this case. The problem is that $this->data looks like this:
View 2 Replies
'Model' => array( /* fields from Model */ ),
'AnotherModel' => array( /* fields from AnotherModel */ )
Within my reusable element, I don't know what model my field belongs to. However, I told this information to the Form Helper when I called $form->create() (in the view that includes the element I'm writing), so it seems like it should be able to tell me. And indeed, the API documentation for the FormHelper class tells of a defaultModel property, but sadly, this property is empty. Now, the simple solution is to pass the model in as a parameter. I can do that. But, I'd like to avoid parameter bloat where I can, and it seems like this ought to be possible, but I can't figure out how. Is there a way?