CGridView Help

Sorry I need help as am new to this framework.

Am having two tables, tbl_orders and tbl_order_status.

One order can have status New, Accepted, Approved and delivered stored.

orderStatus BELONGS_TO Order.

I need to display all orders with a certain status e.g All New orders, All Accepted etc using CGridView widget.

How can I achieve this?

In your Order model:




    public function scopes()

    {


        return array(

            'newOrders'=>array(

                'condition'=>"status=:thestatus",

                'params'=> array(':thestatus' => 'New'),


            ),

            'acceptedOrders'=>array(

                'condition'=>"status=:thestatus",

                'params'=> array(':thestatus' => 'Accepted'),


            ),

            'approvedOrders'=>array(

                'condition'=>"status=:thestatus",

                'params'=> array(':thestatus' => 'Approved'),


            ),

            'deliveredOrders'=>array(

                'condition'=>"status=:thestatus",

                'params'=> array(':thestatus' => 'Delivered'),


            ),

        );

    }

    

Then you can just get all the Approved orders by:


$the_orders = Order::model()->approvedOrders();

Thanks for your response.

I have tried to implement the approach but am still getting some few problems.

I assumed the status in your sample code is the status field in the table tbl_order status.

In my Order model as follows:




  public function scopes()

      {


        return array(

            'newOrders'=>array(

                'condition'=>"order_status.status=:thestatus",

                'params'=> array(':thestatus' => 'New'),




where order_status is the named relation defined in that Order Model as follows




 public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

                    'branches'=>array(self::BELONGS_TO,'Branches','branch_id'),

                    'staff'=>array(self::BELONGS_TO,'Staff','who_created'),

                    'order_items'=>array(self::HAS_MANY,'OrderItems','order_id'),

                    'order_status'=>array(self::HAS_MANY,'OrderStatus','order_id')

		);

	}




In my controller I did as follows (Just as you directed me)




 $newOrders = Orders::model()->newOrders();



Var_dumping $newOrders returns an object type, without records.

Trying to use it in CGridView I get the following




CException


Orders and its behaviors do not have a method or closure named "getData". 



What might I have done wrong?

Did you provide the CGridView a CActiveDataProvider? CActiveDataProvider has a getData method. getData is part of the IDataProvider interface.

:rolleyes: