Children/Parent cakephp

Asked

Viewed 48 times

1

In the code below, I have a Select, that returns all my accommodations that are with parent_id null, which in case would be all accommodations FATHER. But when it comes time to return, I need you to show me the accommodation FATHER and their Children.

Ex.: Room - bathroom - bed - lunch.

How do I get the Children of each accommodation FATHER?

Part of the form select:

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

Code that queries in the controller:

 $acomodacoes = $this->Navigation->find('list',array(
            'conditions' => array(
                'parent_id' => null,
            ),
            'fields' => array(
                'Navigation.nome',
            ),
        ));
  • Do you want to simply get a "run" list of items from these parents without any grouping? Or use the <select> to format in a segmented way?

  • I just want you to show on select the other Children that you’re part of Dad. Because when I save, the id that goes to the database will only be the parent id. I’ve tried with getPath, but it didn’t work..

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 you own parent_id (soon, everyone who has a father) and his <select> will have options with the value being the parent_id and the display text its own name.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.