As far as I know you can't set the default input options at the
constructor level. Although I haven't dug into the code in a while to
make sure of that. If I'm wrong, someone will correct me.
You can go the MyFormHelper class route, which may be the *best*
option IMHO. Just overwrite the create function calling the
parent::create() with a set an array_merge of default options you
want.
class MyFormHelper extends FormHelper {
var $defaults = array('inputDefaults' => array('div' => false));
function create($model = null, $options = array()){
parent::create($model, array_merge($this->defaults, $options));
}
}
Simple as that.
Or you can instead use an element, pass in an array as options to
array_merge with your default options for your form. That is a trick
I like to use often with pagination options and links.
Another option, could be defining a $default_form_options in your
app_controller than you set and use for every form create (adjusting
as needed).
Example:
//app_controller beforeFilter
$this->set('default_form_options', array('inputDefaults' =>
array('div' => false)));
//view
$this->Form->create('Model', array_merge($default_form_options,
array('url' => 'some_where')));
You get the idea...
Hope that helps,
Nick
On Jul 9, 6:48 am, BlueAngel <[email protected]> wrote:
> Hi there everyone,
>
> I would like to know if it's possible to instantiate a helper in a
> controller with configuration options (like one can with components,
> or with model behaviors).
>
> What I'd like to do is pre-set certain options for the Form helper
> (div => false) for example, instead of having to do it each and every
> time I add a form field in the view. I've done a bit of a search in
> the Book, and also on the web, but I've not found anything that lead
> me to an answer.
>
> What I thought, as an alternative, is to write a wrapper helper class
> (e.g. MyForm) that uses the Form helper with wrapper functions around
> each of the Form helper's functions; this approach should work but it
> seems like a long way around solving the problem. I'd like to avoid
> this if possible.
>
> I am in the process of refactoring a site I did about 2 years ago in
> Cake 1.1; I've upgraded to 1.2.7 and plan to upgrade even further to
> 1.3.2 before deploying the updated version of the site. I'm also using
> this as an exercise in improving my own Cake skills, trying to keep
> the code as "cake-like" as possible.
>
> Any pointers in this regard would be much appreciated.
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en