Sessions --> Get User Name?

hi i’m yii user management module & i created data table for my application so when someone insert new data i want to insert his user id Automatically in mt data table how do this

CREATE TABLE IF NOT EXISTS offer_detail (

id int(60) NOT NULL AUTO_INCREMENT,

company_id int(60) NOT NULL,

offertype_id int(60) NOT NULL,

category_id int(60) NOT NULL,

offer_title varchar(150) NOT NULL,

offer_description text NOT NULL,

image varchar(150) NOT NULL,

coupon_id varchar(60) NOT NULL,

price text NOT NULL,

unit_id varchar(10) NOT NULL,

price_now varchar(60) NOT NULL,

from varchar(80) NOT NULL,

to varchar(80) NOT NULL,

[color="#FF0000"]user_id int(60) NOT NULL,[/color]

PRIMARY KEY (id`),

user table (YII user managment modules )

CREATE TABLE IF NOT EXISTS user (

id int(10) unsigned NOT NULL AUTO_INCREMENT,

username varchar(20) NOT NULL,

password varchar(128) NOT NULL,

activationKey varchar(128) NOT NULL DEFAULT ‘’,

createtime int(10) NOT NULL DEFAULT ‘0’,

lastvisit int(10) NOT NULL DEFAULT ‘0’,

lastaction int(10) NOT NULL DEFAULT ‘0’,

lastpasswordchange int(10) NOT NULL DEFAULT ‘0’,

superuser int(1) NOT NULL DEFAULT ‘0’,

status int(1) NOT NULL DEFAULT ‘0’,

avatar varchar(255) DEFAULT NULL,

notifyType enum(‘None’,‘Digest’,‘Instant’,‘Threshold’) DEFAULT ‘Instant’,

PRIMARY KEY (id),

UNIQUE KEY username (username),

KEY status (status),

KEY superuser (superuser)

)

thank you …

First create the User if not created, then get value for user_id as


Yii::app()->user->id

as use it for your next query.

hey first set user id in authentication method.

Then offer_detail controller create() method set it like

$model->user_id=Yii::app()->user->id;

same thing you can do for update also…

Hope it may help you…

thanks it working

public function actionCreate()

{


	$model=new OfferCompany;





	// Uncomment the following line if AJAX validation is needed


	// $this->performAjaxValidation($model);





	if(isset($_POST['OfferCompany']))


	{   $model->User_id=Yii::app()->user->id;


		$model->attributes=$_POST['OfferCompany'];


		if($model->save())


			$this->redirect(array('view','id'=>$model->id));


	}





	$this->render('create',array(


		'model'=>$model,


	));


}

yes i’ll do it

Enjoy :D