Yii Framework Forum: Question about the Yii Book - Yii Framework Forum

Jump to content

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

Question about the Yii Book using SQL statements in your code

#1 User is offline   mari 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 14-March 11

Posted 20 March 2011 - 12:45 PM

I know that many people on this forum used the "Agile web Devopment" book to learn Yii. My question comes is about chapter 8. There they start introducing the RBAC system to assosiate users with roles and such.

For example
/**
* removes an association between the project, the user and the
user's role within the project
*/
public function removeUserFromRole($role, $userId)
{
$sql = "DELETE 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", $userId, PDO::PARAM_INT);
$command->bindValue(":role", $role, PDO::PARAM_STR);
return $command->execute();
}


Now, why would they start mixing SQL status, and use the Yii::app()->db->functions.
I mean wouldn't it be better to completely keep SQL statements out of your code with the Yii automated codes? For example - Wouldn't it be better to create a Controller for the new tbl_project_user_role and use actionCreate, actionDelete, actionUpdate auto-generated methods to interact with that database?

Why the sudden change to specific SQL querys? Is it just simpler to explain or there is a OOP approach I am not understanding here?
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,317
  • Joined: 12-October 09
  • Location:Croatia

Posted 20 March 2011 - 03:16 PM

NOTE: moved to proper section
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   caramelon 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 35
  • Joined: 19-January 11
  • Location:Neandertal

Posted 21 March 2011 - 04:12 AM

mari,

wait until you get to chapter 9. You'll encounter another way to retrieve data.

On a separate note: what's wrong with using sql queries?
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