Yii Framework Forum: CGridView, textfield and button question - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CGridView, textfield and button question Rate Topic: -----

#1 User is offline   Diodoliz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 13-December 10

Posted 13 December 2010 - 02:31 AM

Hey guys,

I'm kind of stuck with this issue, looked around forums for a while and really couldn't find any good solutions for this..

Here is my code

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(
      array(
        'class'=>'CLinkColumn',
        'header'=>'Product Name',
        'labelExpression'=>'$data->product->product_name',
        'urlExpression'=>'Yii::app()->createUrl("product/view", array("id"=>$data->id_product))',
      ),
      array( //TextBox --- Displays quantity
        'header'=>'Quantity',
        'value'=>'CHTML::activeTextField($data,\'quantity\')',
        'type'=>'raw',
        'htmlOptions'=>array('width'=>'40px'),
      ),
      array( //Update button - Doesn't work - nothing in post..
        'value'=>'CHTML::button(\'Update\',  array(\'submit\' => Yii::app()->createUrl("cart/update", array("id"=>$data->id_product))))',
        'type'=>'raw',
        'htmlOptions'=>array('width'=>'40px'),
      ),
      array( //Remove button - Works just fine
        'value'=>'CHTML::button(\'Remove\',  array(\'submit\' => Yii::app()->createUrl("cart/remove", array("id"=>$data->id_product))))',
        'type'=>'raw',
        'htmlOptions'=>array('width'=>'40px'),
      ),
    ),
)); ?>


Here is what i'm trying to do

When you hit update button it takes you to the right page, but my $_POST array is empty

I'm trying to make it so you change the number in textbox and hit update, you get re-directed and $_POST[] variable is = to the value of that textbox.
0

#2 User is offline   Diodoliz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 13-December 10

Posted 13 December 2010 - 12:48 PM

Anyone??
0

#3 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,159
  • Joined: 04-October 09
  • Location:Moscow

Posted 14 December 2010 - 02:06 AM

Try includind the CGridView in a form.
0

#4 User is offline   Diodoliz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 13-December 10

Posted 14 December 2010 - 12:18 PM

Exactly what I ended up doing:

<?php 

echo CHtml::beginForm();

$this->widget('zii.widgets.grid.CGridView', array(
    'dataProvider'=>$dataProvider,
    'columns'=>array(
      array(
        'header'=>'Quantity',
        'value'=>'CHTML::textField($data->id_product,$data->quantity,array(\'width\'=>20,\'maxlength\'=>3))',
        'type'=>'raw',
        'htmlOptions'=>array('width'=>'20px'),
      ), 
      array(
        'class'=>'CLinkColumn',
        'header'=>'Product Name',
        'labelExpression'=>'$data->product->product_name',
        'urlExpression'=>'Yii::app()->createUrl("product/view", array("id"=>$data->id_product))',
      ),
      array(
        'header'=>'Price',
        'value'=>'($data->product->price)*($data->quantity)',
        'htmlOptions'=>array('width'=>'40px'),
      ),       
      array(
        'value'=>'CHTML::button(\'Remove\',  array(\'submit\' => Yii::app()->createUrl("cart/remove", array("id"=>$data->id_product))))',
        'type'=>'raw',
        'htmlOptions'=>array('width'=>'40px'),
      ),
    ),
));

echo CHTML::button('Update cart',  array('submit' => Yii::app()->createUrl("cart/update")));

echo CHTML::button('Checkout',  array('submit' => Yii::app()->createUrl("order/getInfo")));

echo CHtml::endForm(); 

?>

1

#5 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,159
  • Joined: 04-October 09
  • Location:Moscow

Posted 14 December 2010 - 01:26 PM

And did it work properly?
0

#6 User is offline   Diodoliz 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 13-December 10

Posted 14 December 2010 - 05:55 PM

 zaccaria, on 14 December 2010 - 01:26 PM, said:

And did it work properly?


worked like a charm!
0

#7 User is offline   fiela 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-January 13

Posted 29 January 2013 - 06:46 AM

 Diodoliz, on 14 December 2010 - 05:55 PM, said:

worked like a charm!


do you mind sharing your controller file as well wanna see how you saved it into the db
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users