-- Table structure for table `cats`
--
CREATE TABLE IF NOT EXISTS `cats` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) COLLATE utf8_persian_ci NOT NULL,
`status` int(2) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci
AUTO_INCREMENT=4 ;
--
-- Dumping data for table `cats`
--
INSERT INTO `cats` (`id`, `title`, `status`) VALUES
(1, 'cat1', 1),
(2, 'cat2', 1);
-- --------------------------------------------------------
--
-- Table structure for table `subcats`
--
CREATE TABLE IF NOT EXISTS `subcats` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`cat_id` int(11) NOT NULL,
`title` varchar(255) COLLATE utf8_persian_ci NOT NULL,
`status` int(2) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci
AUTO_INCREMENT=4 ;
--
-- Dumping data for table `subcats`
--
INSERT INTO `subcats` (`id`, `cat_id`, `title`, `status`) VALUES
(1, 2, 'sub2-1', 0),
(2, 2, 'sub2-2', 0),
(3, 1, 'sub1-1', 0);
and i have 2 controller:
subcats_controller
cats_controller
and my model:
subcat:
var $belongsTo = array(
'Cat' => array(
'className' => 'Cat',
'foreignKey' => 'cat_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
cat:
var $hasMany = array(
'Subcat' => array(
'className' => 'Subcat',
'foreignKey' => 'cat_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
and in view:
echo $form->input('usercats');
and in subcats_controller:
function usercat() {
$usercats = $this->Subcat->Cat->find('all');
$this->set(compact('usercats'));
}
and i want create this:
<select>
<optgroup label="cat1">
<option value="3">sub1-1</option>
</optgroup>
<optgroup label="cat2">
<option value="1">sub2-1</option>
<option value="2">sub2-2</option>
</optgroup>
</select>
i hope this information can help you,to help me
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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment