AD
On Wednesday, 20 March 2013 03:28:09 UTC+1, mk wrote:
-- On Wednesday, 20 March 2013 03:28:09 UTC+1, mk wrote:
Hi
I am having some trouble getting a self association parent_id to show up in the scaffolding drop down list of a view.
I have the following baked add action in my controller
public function add() {
if ($this->request->is('post')) {
$this->Item->create();
if ($this->Item->save($this->request->data)) {
$this->Session->setFlash(__('The item has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The item could not be saved. Please, try again.'));
}
}
$parentItems = $this->Item->ParentItem->find('list');
$collections = $this->Item->Collection->find('list');
$this->set(compact('parentItems', 'collections'));
}
This passes parentItems and collections to my view (add.ctp) but the view outputs an empty dropdown box for "parent_id"
<fieldset>
<legend><?php echo __('Add Item'); ?></legend>
<?php
echo $this->Form->input('parent_id');
echo $this->Form->input('collection_id');
echo $this->Form->input('name');
?>
</fieldset>
Does anyone have an idea what I am doing wrong? I have the following associations setup in my model
Item Model/Item.php - contains columns id, parent_id, lft, rght & name
public $belongsTo = array(
'ParentItem' => array(
'className' => 'Item',
'foreignKey' => 'parent_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
public $hasMany = array(
'ChildItem' => array(
'className' => 'Item',
'foreignKey' => 'parent_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
),
I also see the parentItems array in the variables of the debug toolkit so I know they are there... just need to know how to show the "name" for each "parent_id"
Thanks in advance for any help.
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment