Question about the Yii Book

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?

NOTE: moved to proper section

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?