تعریف کاربران ثبت نام شده برای دسترسی

[rtl]سلام. تو کد زیر در صورتی که من گروهی داشته به اسمهای ادمین و پادلیشر چطوری میتونم این گروه های خاص رو تعریف و دسترسی بدم؟[/rtl]


	public function accessRules()

	{

		return array(

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

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

				'users'=>array('*'),

			),

			array('allow', // allow authenticated users to access all actions

				'users'=>array('@'),

			),

			array('deny',  // deny all users

				'users'=>array('*'),

			),

		);

	}

[rtl][font="Tahoma"]بجای * و @ میتونی اسم یوزرت رو بنویسی.

بیشتر:

http://www.yiiframework.com/doc/guide/1.1/en/topics.auth#access-control-filter

برای دسترسی های پیچیده تر پیشنهاد میکنم از Role-Based Access Control استفاده کنی:

http://www.yiiframework.com/doc/guide/1.1/en/topics.auth#role-based-access-control[/font][/rtl]

[RTL]

این که فرمودید به جای یوزر اسم بنویسیم چطوری میتونیم یه رکورد از دیتابیس رو بهش معرفی کنیم؟

مثلا آی دی کاربری که مثلا تایپش ادمین خورده یا پابلیشر خورده مثلا

[/RTL]

[rtl]در این صورت پیشنهاد من Role-Based Access Control هست که لینک راهنماشو بالا دادم

[/rtl]

[font="Tahoma"][rtl]

البته یک راه حل خیلی ساده تر و سبک تر از Role-Based Access Control هم هست که برای بیشتر موارد جواب میده.

به صورت زیر

[/rtl]




Two things about this expression. First, you still need to use the users element, 

and you’ll probably want to still restrict this to logged-in users (most likely). 

Second, the expression itself should be some PHP code, quoted,

that when evaluated gives a Boolean result.

If the code in the expression will be true, then permission will be allowed; false, denied.

Say you wanted to restrict the publish action to only those with the role of editor:


array('allow',

    'actions'=>array('publish'),

    'users'=>array('@'),

    'expression'=>'isset($user->role) && ($user->role==="editor")'

),



[rtl]

مراجعه شود به Framework Access Control Lists- Larry Ullman

[/rtl][/font]