I am a bit new to the Yii Framework. I am making a product selling website, which has 3 basic models
-
Users model containing the primary key id
-
Products model containing the primary key id
-
Orders model which is basically a mapping between the products and orders. It contains the fields product_id and user_id as foreign keys.
I have made a page where all the products are populated and the logged in user can click on a button on product box to order a particular product.
the code of the link is like this
<?php echo CHtml::link('Order Now',array('order', 'product_id'=>$model->id, 'user_id'=>Yii::app()->user->id)); ?>
b[/b] This is sending a GET request but I want to sent the details as post request. How to do this?
My default controller is the site controller. I have made an actionOrder method in this controller. The code is:
if(Yii::app()->user->isGuest){
$this->redirect('login');
}else{
$model=new Orders;
if(isset($_POST['products_id']))
{
$model->attributes->products_id=$_POST['product_id'];
$model->attributes->users_id=Yii::app()->user->id;
if($model->save())
$this->redirect(array('index'));
}
$this->render('index');
}
But this code is showing bunch of errors. Also, b[/b] how can I put both
products_id
and
users_id
in a single array Orders so that I just have to write
$_POST['orders']
Also, b[/b] how can I display a flash message after the save is successful?
Kindly help me to solve my 3 problems and sorry if you feel that the questions are too stupid.