Certain databases not connecting

Hello

I started in on “the book” this weekend but hit a stumbling block in Chapter 8. I have been comparing my code with the examples in the book to try to figure this out on my own but I’m still having no luck.

I don’t seem to be able to insert into either the tbl_project_user_assignement or tbl_project_user_role tables. Consequently, I cannot get the proper assignments or authorization I need on a project by project basis. Perhaps I simply misunderstood what I was reading but I expected to find rows being inserted in both these tables as I added projects.

I can successfully create projects but that’s about it.

If I had to guess, and that’s about where my skilllevel is right now… It appears as though these statements aren’t being executed.





/** * creates an association between the project, the user and the

	user's role within the project */

	public function associateUserToRole($role, $userId)

	{

		$sql = 'INSERT INTO tbl_project_user_role (project_id, user_id, role) VALUES (:projectId, :userId, :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();	//p.192 Note: book incorrectly leaves () off of execute

	}



But all these methods appears to be in order as far as I can tell.

Here are some of the steps I have taken:

Careful comparison of my code with the example code provided with the book.

Rebuilt the tbl_project_user_assignement and tbl_project_user_role tables using the InnoDB engine. I originally built them with the default MyISAM engine and I think that’s why the foreign keys were not there. I reassigned the foreign keys.

Can anyone suggest other places in the code I should investigate?

Currently, this code is only executed as part of adding users to projects (as opposed to when adding a new project). Arguably, the user creating the new project should automatically be made the "owner" of the project they are creating. However, since project creation was covered in chapter 6 and this new RBAC implementation is two chapters later, we did not go back and alter any of the Project CRUD in the book.

Are you just expecting this to execute when you create a new project, or are you getting an explicit error when attempting to add a new user to a project?

Hi Jeff

Thank you for your reply I am not getting any errors, I made the assumption that the code would execute when I created a new project. I’m not that proficient in php yet so I didn’t fully understand the nature of the code.

It’s an excellent book, In hindsight I’m even happy to have spent a couple of days pouring over code to trying to confirm an assumption, it gave me a chance to absorb more of what I had been studying.

But how would one tackle this issue?

I tried adding this to ProjectTest::testCreate()


	$user = User::model()->findByAttributes(array('username'=>$this->username));

	$this->projects->associateUserToProject($user);

	$this->projects->associateUserToRole($this->role,$user);

But when running unit test I was met with this error:

  1. ProjectTest::testCreate

Exception: Unknown property ‘username’ for class ‘ProjectTest’.

If you could just point me in the right direction, or even better, give an example code - it would be great! I am at the end on chapter 12, but it is all too hazy for me. Especially the rbac part.