Yii Framework Forum: Creating simple model - Yii Framework Forum

Jump to content

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

Creating simple model Rate Topic: -----

#1 User is offline   dckurushin 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 392
  • Joined: 16-March 11
  • Location:Israel

Posted 24 September 2011 - 06:28 AM

There is two kinds CFormModel and CActiveRecord

But if I dont want to use form on this model and dont want a.r. just need to access db the DAO way, what should I extend?

or I don't need to extend any thing?

cause the db access is via Yii::app()->db so I have all what I need...
0

#2 User is offline   Francis.TM 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 55
  • Joined: 19-April 10
  • Location:China. RP.

Posted 24 September 2011 - 06:41 AM

extends from CModel;
0

#3 User is offline   dckurushin 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 392
  • Joined: 16-March 11
  • Location:Israel

Posted 24 September 2011 - 06:51 AM

When attributeNames are used?
If I extend CModel I need to implement it ,because CModel is abstract
can I just leave it blank? what is his role?

I think I should create Model That extends CModel, because the abstractness of CModel and the attributeNames method that not implemented will cause me to create a lot of additional code in every custom model...

So this is the way I'll go
0

#4 User is offline   Yii Apprentice 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 30-June 11

Posted 24 September 2011 - 07:31 AM

being an apprentice i can not give you much help, but this function could be some sort of hint?

Yii doesn't want the users to use direct database operations, not safe, not efficient. these operations are all encapsulated into CDbConnection and CDbCommand.

public function isUserInRole($role)
{
$sql="select role from tbl_project_user_role where project_id=:projectId and user_id=:userId and role=:role";
$command=Yii::app()->db->createCommand($sql);
$command->bindValue(":projectId",$this->id, PDO::PARAM_INT);
$command->bindValue(":userId",Yii::app()->user->getId(), PDO::PARAM_INT);
$command->bindValue(":role",$role, PDO::PARAM_STR);
return $command->execute()==1?true:false;		
}

Yii, powerful yet difficult to harness.
0

#5 User is offline   dckurushin 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 392
  • Joined: 16-March 11
  • Location:Israel

Posted 24 September 2011 - 07:35 AM

In yii you have Yii::app()->db this is a CDbConnection instance and than you can use dao or query builder or what ever.

I just need the separation to make it "mvc" :lol: and not VC ::)
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