Multiple access rules for one view

Hi,

I have a view that is used for 2 things:

  1. Show some data. This action should be available to all users.

  2. Add some new data (there is a form at the bottom). This should only be available to logged in users.

So the form should be visible to all users, but when the user submits the data he should be rerouted to

the login-page (as if it was restricted in the accessRules()).

What would be the best way to do this? I know how to use filters and access-rules, but i’m not sure how

to apply them to a controller action that does 2 separate things.

Any pointers are appreciated!

Cheers, JJ

Ok, First create a form on a View file and give a action to it.and to show this form on a view file.Just use a




 if(! Yii::app()->user->isGuest){

 // show a form code here.

}




;)

Yii::app()->user->isGuest return true if a Webuser is a Guest user and not logged in on the site. :)

let it check…!!!

Hi jayant,

Thanks for your quick reply :slight_smile:

I think what you suggest would work if I would just hide the form if the user is nog logged in, right?

But i want the form to be always rendered. Only after hitting the submit button should it check

if the user is logged in or guest. If it’s a guest it should redirect to the login page.

Any idea?

Cheers, JJ

Yes exactly…!!

ok now give a action to the form and define this action name access rule.try this and share your views.

I’m not sure if I entirely follow you :slight_smile:

The page is /model/view and the action for this in the controller is actionView.

I use a renderPartial for the form (something like model/_form). As far as I understand Yii, the action

for the form is now also actionView.

Did you mean in your reply that you can assign a separate action to the partial _form?

Cheers, JJ

The framework doesn’t limit your ability to assign an arbitrary action to a form:

CActiveForm:$action

CHtml::beginForm()

Ah, I see. Now I understand what jayant was trying to tell me too!

Thanks a lot guys. This is what I needed.

Cheers, JJ

Yes exactly…this what i was trying to tell you as phtamas said. :)

thats good if you got the concept.;)