Question

In my form model I have this:

class UpdateForm extends Form {
    public function __construct($name = null) {
        parent::__construct('updateForm');

        $this->setAttribute('method','post');  

        $this->add(array(
            'name' => 'response',
            'attributes' => array(
                'type' => 'textarea',
            ),
            'options' => array(
                'label' => 'Response',
            ),
        ));...

In my view I was doing this:

$form->get('response')->setAttributes(array(
        'class' => 'form-control',
        'placeholder' => '--- Enter your response here ---'
    ));

I found I can set the class of a specific form input in my Form model by just doing:

$this->add(array(
    'name' => 'response',
    'attributes' => array(
        'type' => 'textarea',
        'class' => 'fart',
    ),...

But now I wonder if this is wise. Should I do this in the view or does it matter (assuming I am trying to adhere to MVC best practices)

Was it helpful?

Solution

Both of the options are valid.

I am not sure which one best fits the MVC approach but here's what I do. If I am working in a team and if someone else is handling the design of the application, I will add these CSS classes in the view. So the designer can change them if he/she wants to.

If I am most likely to work with a developer I assign the CSS classes in the model. And leave a comment in the view pointing out the location of the file where the classes are assigned.

Hope this help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top