Yii directory structure and session questions

Hi Everyone,

I’m currently building a job search application and I’ve got a few questions regarding to my directory set up and hope someone could enlighten me a bit here.

The application will have three types of user jobseeker, advertiser and administrator.

I have currently set up my directory structure like below:

/

common/

— components/

— config/

— models

jobseeker/

— components/

— config/

— controllers/

— models/

— views/

— www/

 ----- assets/


 ----- js/


 ----- images/


 ----- css/

advertiser/ <-- same structure as jobseeker

admin/ <-- same structure as jobseeker

So my domain example.com will point to jobseeker/www and my sub domain advertiser.example.com will be point to advertiser/www and my admin.example.com to admin/www

My questions are below:

  1. If I need to share css, js and images how can I put it into common so that all three application can use it? should I just create symlink in all the individual application’s js, css, images folder to point to the ones in common? or should I just duplicate the js, css and images files that needed to be share in each of the application?

  2. Initially I was hoping to just use one application instead of separating to three, but I was stuck in figuring out how to have multiple CWebuser and at the same time making use of the built in accesscontrol filter as well. This is because advertiser and jobseeker are different and they both requires different login. So you can be logged in as advertiser and jobseeker but with different username and password. I did read through the role base access wiki but that wouldn’t solve my problem if jobseeker and advertiser can both be logged in but with two different login detail. But if I separate them into separate application then each one of them can have their own session. Is there a better way in accomplishing this?

Anyway help or suggestions will be greatly appreciated. Thanks!

Hi!

What a problem?

Yo should use one application, you don’t need three applications =)

I think:

You should have table in database with information of users - their usernames, passwords etc. You will have three roles - admin, jobseeker and advertiser. Users will have their roles. What a problem? Every user have it’s own session, You don’t need to separate anything.

Access control filter might be something like this:


public function accessRules()

	{

		return array(

			array('allow',  // allow all users to perform 'index' and 'view' actions

				'actions'=>array('index','view'),

				'roles'=>array('advertiser'),

			),

                        array('allow',  // allow all users to perform 'index' and 'view' actions

				'actions'=>array('create','update'),

				'roles'=>array('ajobseeker'),

			),

                        ...

                       )

        }




Just create different controller actions (methods) for different users, if You need, and be happy =)

Hi Lyne, thank you for your reply.

Yes, the role based solution like you have mentioned would have solved the problem if jobseeker and advertiser doesn’t require a separate login.

What my problem is, if you were a registered advertiser say with the username ‘justatest’ and already logged into the system, then when you go to the jobseeker page it should still require you to login with a different set of login detail. So I will need to have two CWebUser to exist at the same time in session and have access control to know which one to use while doing the filter, but I’m not sure how to do that.

anyone else have any other suggestions and advice? thanks

Just an idea, i’m not sure if it actually works.

Implement jobseeker, advertiser and admin as a module. Configure an "user" component in each of them but with different cookie configuration. Extend CWebApplication and override getUser() method:




public function getUser()

{

	if ($module = $this->controller->module && $module->hasComponent('user')) {

		return $module->getComponent('user');

	}

	return parent::getUser();

}



May worth a try.

Sorry, maybe I understand You incorrect, because English is not my native language, but if i understand correct:

You can assign one user with many roles, and role can have another role as child. Your user can have roles ‘Advertiser’ and ‘Jobseeker’. Also You can add business rules (bizRule), something like this:




...

$auth=Yii::app()->getAuthManager();

$bizRule = '$resume->author->id==Yii::app()->user->id';

$task = $auth->createTask('updateOwnData', 'Update own data', $bizRule);

$role = $auth->createRole('jobseeker');

$role->addChild('updateOwnData');

$role = $auth->createRole('advertiser');

$auth->assign('advertiser','justatest');

$auth->assign('jobseeker','justatest');

$auth->save();



It’s only example how to use authManager.

Whatever, be sure You don’t need three applications, you don’t need separate anything. Begin to write your application, and when You will have some problems, post your code, describe your problem in this forum, and you will have the best solution - Yii community members are very kind people ;)