rii
rii

Reputation: 57

placeholder attribute in zf2

How could insert the value of a field's db in the plcaholder in zf2

<div class="form_element">
<?php
    $this->placeholder('name')->data = $this->data;  
    $name = $form->get('name');
    echo $formLabel->openTag().$name->getOption('label')." ";   
        echo $this->formInput($name);
        echo $formLabel->closeTag();
?>
</div>

Upvotes: 0

Views: 234

Answers (1)

AlexP
AlexP

Reputation: 9857

A placeholder is a ViewHelper and therefore is is designed to help render view content.

In order to use your database data witin a placeholder you will need to ensure that the data is first passed to the view from the controller action.

public function modificaAlumnoAction()
{
  //...
  return ViewModel('data' => $data); // data passed to the view instance 
}

Then within the view script

// modifica-alumno.phtml
$this->placeholder('foo')->data = $this->data;

An finally output the data (such as within the layout)

// layout.phtml
echo $this->placeholder('foo)->data;

Upvotes: 1

Related Questions