On Thu, Oct 21, 2010 at 8:12 AM, Philip <[email protected]> wrote:
> Hi,
>
> I'm sorry if this has been answered elsewhere but I've done a bit of
> googling and can't seem to find this situation.
>
> I've got a table which refers back to itself. It's a table of
> geographical locations (territories) and each territory may have a
> parent territory which it is a part of.
>
> I've got a parent_id field in the territory table and I used bake to
> generate my view, model and controller.
>
> However, while I can add a territory, when doing so the Parent drop-
> down menu doesn't seem to populate with the other territories.
>
> I'm using PHP 5, Cake 1.3.4 running locally in MAMP.
>
> These are, I believe, the relevant sections of code and (as one would
> expect from auto-generated code) they seem to match the other examples
> I can find online:
>
> From territory.php
>
> var $belongsTo = array(
> 'ParentTerritory' => array(
> 'className' => 'Territory',
> 'foreignKey' => 'parent_id',
> 'conditions' => '',
> 'fields' => '',
> 'order' => ''
> ),
>
>
> and
>
> var $hasMany = array(
> 'ChildTerritory' => array(
> 'className' => 'Territory',
> 'foreignKey' => 'parent_id',
> 'dependent' => false,
> 'conditions' => '',
> 'fields' => '',
> 'order' => '',
> 'limit' => '',
> 'offset' => '',
> 'exclusive' => '',
> 'finderQuery' => '',
> 'counterQuery' => ''
> )
>
>
> from territories_controller.php
>
> $parentTerritories = $this->Territory->ParentTerritory->find('list');
>
> and from the add.ctp view:
>
> echo $this->Form->input('parent_id');
You have to specify the data for the options.
echo $this->Form->input('parent_id', array('options' => $parentTerritories));
Make sure you're first setting that variable for the view:
$this->set(
'parentTerritories',
$this->Territory->ParentTerritory->find('list')
);
> Does anyone have any idea why the Parent field in the add view
> doesn't seem to contain anything given that I have added a few
> territories without parents?
>
> It doesn't even show the parent if I manually edit the DB to give a
> territory a parent, although the parent will still be displayed on the
> "view territories" page.
>
> Thanks for your help
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en