Your question is not very clear to me.
Here is my code details:
categories Table:
`categoryId` int(10) NOT NULL auto_increment,
`categoryName` varchar(100) NOT NULL,
`isActive` enum('Y','N') NOT NULL default 'Y',
PRIMARY KEY (`categoryId`)
products Table:
`productId` int(10) NOT NULL auto_increment,
`productName` varchar(20) NOT NULL,
`categoryId` int(10) NOT NULL,
`isActive` enum('Y','N') NOT NULL default 'Y',
PRIMARY KEY (`productId`)
It is my product Model
class product extends AppModel
{
var $name = 'Product';
var $primaryKey = 'productId';
var $validate = array(
'productName' => VALID_NOT_EMPTY,
);
var $belongsTo = array(
'Category' => array(
'className' => 'category',
'foreignKey' => 'categoryId',
)
);
}
and it is my category model:
class category extends AppModel
{
var $name = 'Category';
var $primaryKey = 'categoryId';
var $validate = array(
'categoryName' => VALID_NOT_EMPTY,
);
}
my product controller is-
$categories = $this->Product->Category->find('list',
array( 'conditions' => array('isActive' => 'Y')));
$this->set(compact('categories'));
And view -
<?php echo $form->select('Product.categoryId', array('options' =>
$categories)); ?>
But it is giving html like this-
<select name="data[Product][categoryId]" id="ProductCategoryId">
<option value=""></option>
<optgroup label="options">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</optgroup>
</select>
But as per my requirement it should be
<select name="data[Product][categoryId]" id="ProductCategoryId">
<option value="">Select</option>
<option value="1">CategoryName1</option>
<option value="2">CategoryName2</option>
<option value="3">CategoryName3</option>
</select>
On Jul 9, 5:02 pm, "Jonathan Snook" <[EMAIL PROTECTED]> wrote:
> Do you have a displayField set or a field called name?
>
> On Wed, Jul 9, 2008 at 2:02 AM, kaushik <[EMAIL PROTECTED]> wrote:
>
> > Thank you for this help.As per your advice i have changed my
> > controller to -
>
> > $categories = $this->Product->Category->find('list',
> > array( 'conditions' => array('isActive' => 'Y')));
> > $this->set(compact('categories'));
>
> > And view -
>
> > <?php echo $form->select('Product.categoryId', array('options' =>
> > $categories)); ?>
>
> > But it is giving html like this-
>
> > <option value=""></option>
> > <optgroup label="options">
> > <option value="1">1</option>
> > <option value="2">2</option>
> > <option value="3">3</option>
>
> > </optgroup>
> > </select>
>
> > But as per my requirement it should be
>
> > <option value="">Select</option>
> > <option value="1">CategoryName1</option>
> > <option value="2">CategoryName2</option>
> > <option value="3">CategoryName3</option>
> > </select>
>
> > What change I have to do? Plz help me.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---