Ejercicio buscar por edad

Controlador:

 public function edad($inicio = 0, $fin = 30) {
 
 if (!empty($this->request->query['inicio'])) {
 $inicio = $this->request->query['inicio'];
 }
 if (!empty($this->request->query['fin'])) {
 $fin = $this->request->query['fin'];
 }

 $params = array(
 'conditions' => array('Autor.edad BETWEEN ? AND ? ' => array($inicio, $fin)),
 'recursive' => -1,
 'order' => 'Autor.edad',
 );
 $autores = $this->Autor->find('all', $params);

 $this->set(compact('autores', 'inicio', 'fin'));
 }

La vista:

<div class="autors view">
 <h2><?php echo __('Autores entre ' . $inicio . " y " . $fin); ?></h2>
 <?php
 echo $this->Form->create('Edad', array('type' => 'get',
 'url' => array('controller' => 'Autors', 'action' => 'edad')));
 echo $this->Form->input('inicio', array(
 'label' => 'Introduzca la edad de inicio',
 'default'=>$inicio,
 ));
 echo $this->Form->input('fin', array(
 'label' => 'Introduzca la edad final',
 'default'=>$fin,
 ));
 echo $this->Form->end('Buscar');
 ?>
 <?php
 foreach ($autores as $autor):
 ?>
 <dl>
 <dt><?php echo __('Id'); ?></dt>
 <dd>
 <?php echo h($autor['Autor']['id']) . " " . h($autor['Autor']['name']); ?>
 &nbsp;
 </dd>
 <dt><?php echo __('Edad'); ?></dt>
 <dd>
 <?php echo h($autor['Autor']['edad']); ?>
 &nbsp;
 </dd>
 </dl>
 <?php
 endforeach;
 ?>
</div>

Publicado por

Avatar del usuario

Juan Pablo Fuentes

Formador de programación y bases de datos