I want to change the class of a field in a form in view from the CONTROLLER.
I have some field in example.ctp
echo $form->input(foo',array('label'=>'foo:'));
I want to change the class of this 'foo' from exampleController.php.
How can i do that ?
this would break the MVC structure; as all presentation logic should go in the view.
You could do this however:
// controller
$this->set('foo', 'some_class');
// view
$this->Form->input('foo', array('class' => $foo));
First you need to set class from controller
Controller
$this->set('class_name', 'is_td');
View
echo $this->Form->input('foo.name', array('div' => $class_name));
This will generate
<div class="is_td">
<label for="FooName">Name</label>
<input name="data[foo][name]" type="text" value="" id="UserName" />
</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.