Children / Parent cakephp

1

In the code below, I have a Select , which returns all my accommodations that are parent_id null , which in this case would be all the PAI accomodations. But when it comes back, I need you to show the accommodation PAI and your children .

Eg: Bedroom - bathroom - bed - breakfast.

How do I get the children of each accommodation PAI ?

Part of form select:

  <?= $this->Form->input('acomodacao',array(
                            'type' => 'select',
                            'options' => $acomodacoes,
                            'class' => 'form-control',
                            'empty' => 'Escolha uma acomodação'
                            )); 
                        ?>

Code that queries the controller:

 $acomodacoes = $this->Navigation->find('list',array(
            'conditions' => array(
                'parent_id' => null,
            ),
            'fields' => array(
                'Navigation.nome',
            ),
        ));
    
asked by anonymous 15.04.2015 / 17:31

1 answer

1

From what I understand, you need something like this in your Controller :

$acomodacoes = $this->Navigation->find('list', array(
    'conditions' => array(
        'parent_id <>' => null,
        ),
    'fields' => array(
        'Navigation.parent_id',
        'Navigation.nome'
        ),
    ));

That is, you will get a list of items that have parent_id (so everyone has a parent) and your <select> will have options with value being parent_id and display text the name itself.

    
15.04.2015 / 17:51