hi nachopitt,
//Part of Add View
<?php
echo $this->Form->create('Stock');
?>
<table id="form_table" border="0" cellpadding="0" cellspacing="1">
<tr>
<td class="form_title">Category:</td>
<td><?php echo $this->Form->input('category_id',
array('options' => $sectors, 'label' => false));?></td>
</tr>
<tr>
<td class="form_title">Product name [EN]:</td>
<td><?php echo $this->Form-
>input('product_name' ,array('label'=>false));?></td>
</tr>
<tr>
<td class="form_title">Ranking:</td>
<td><?php echo $this->Form->input('ranking',
array('default'=>0, 'label'=>false));?></td>
</tr>
<tr>
<td class="form_title">Status:</td>
<td>
<?php
$options=array('A'=>'Active','I'=>'Inactive');
$attributes=array('value'=>'A','fieldset'=>false,'legend'=>false,
'separator' =>' ');
echo
$this->Form->radio('status',$options,$attributes);
?>
</td>
</tr>
</table>
<fieldset>
<legend style="padding:5px"><h2>Details</h2></legend>
<table border="1">
<tr><td>Description:</td><td><?php echo $this->Form-
>input('StockDetail.description', array('type'=>'text',
'label'=>false));?></td></tr>
<tr><td>Location:</td><td><?php echo $this->Form-
>input('StockDetail.location', array('type'=>'text', 'label'=>false));?
></td></tr>
</table>
</fieldset>
<?php
echo $this->Form->submit('Save', array('div'=>false, 'class' =>
'submitbutton', 'title' => 'Save record'));
echo $form->button('Reset', array('type'=>'reset',
'class'=>'resetbutton') );
echo $this->Form->end();
?>
Thanks.
Best regards.
On Apr 20, 9:54 pm, nachopitt <[email protected]> wrote:
> Paste your add/edit view code please.
>
> On 19 abr, 15:33, jackgoh <[email protected]> wrote:
>
>
>
> > Hi,
>
> > Model:
> > // Stock model
> > //======================
> > class Stock extends AppModel
> > {
> > var $name = 'Stocks';
> > var $belongsTo = array(
> > 'Category' => array( 'className' => 'Category',
> > 'conditions' => array('Category.id = category_id'),
> > )
> > );
>
> > var $hasOne = array('StockDetail' => array( 'className' =>
> > 'StockDetail' ));
>
> > }
>
> > // StockDetail model
> > //======================
> > class StockDetail extends AppModel
> > {
> > var $name = 'Stock_details';
> > var $belongsTo = array(
> > 'Stock' => array( 'className' =>
> > 'Stock',
> > 'foreignKey' => '',
> > 'conditions' => array('Stock.id = stock_id')
> > )
> > );
>
> > }
>
> > // Stock Controller
> > //==================
> > function edit($id = null) {
> > $this->Stock->id = $id;
> > $catergorys = $this->Stock->Category->find('list',
> > array( 'fields' =>
> > array('id','combined_shortname'),
> > 'conditions' => array('status'
> > => 'A') )
> > );
> > $this->set(compact(catergorys));
> > if (empty($this->data)) {
> > $this->data = $this->Stock->find( array('Stock.id'
> > => $this->Stock->id ));
>
> > } else {
> > $this->Stock->save($this->data['Stock']);
> >
> > $this->StockDetail->save($this->data['StockDetail']);
> > $this->Session->setFlash('Your post has been
> > updated.');
> > // add redirect here...
> > }
> > }
>
> > Everything goes fine to display the data in Viewe, but it is not
> > working when update the record, the data in StockDetail table is not
> > updated, the record is ONLY updated in Stock table.
>
> > I tried saveAll(), but it insert a new record for Stock Only. I tried
> > $this->StockDetail->save($this->data)...
>
> > Thanks for helping me.
>
> > Best regards.- Hide quoted text -
>
> - Show quoted text -
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php