2012-11-03 6 views
2

저는 yii에서 매우 새로 왔습니다.yii에서 기본 홈페이지를 설정하는 방법은 무엇입니까?

사용자 역할에 따라 내 사이트에 기본 홈페이지를 설정하려면 어떻게해야합니까? 무슨 방법이 yii에 사용됩니다.

내가 한 것은 인덱스 동작에서 인덱스 파일을 렌더링하는 것입니다. 그러나 나는 어떻게 그것을 롤베이스화할 수 있습니까?

public function actionIndex() { 
    $this->render('index'); 
} 

도움이 필요하십니까?

답변

3

아마도 지금 생각했지만 대답을 게시하지 않았을 것입니다. 다만 이것이 누군가를 돕는 경우에, 1 개의 실시는 다음과 같이이다. 이 작업을 수행하는 RBAC에 구현 된 것이 있는지는 모르겠지만 구현하기에 충분히 간단합니다./컨트롤러/SiteController.php 변화 1 개 라인 보호되는 파일에서

:

public function actionLogin() 
{ 
    $model=new LoginForm; 

    // if it is ajax validation request 
    if(isset($_POST['ajax']) && $_POST['ajax']==='login-form') 
    { 
     echo CActiveForm::validate($model); 
     Yii::app()->end(); 
    } 

    // collect user input data 
    if(isset($_POST['LoginForm'])) 
    { 
     $model->attributes=$_POST['LoginForm']; 
     // validate user input and redirect to the previous page if valid 
     if($model->validate() && $model->login()) 
      //$this->redirect(Yii::app()->user->returnUrl); change this 
         $this->roleBasedHomePage(); //to this 
    } 
    // display the login form 
    $this->render('login',array('model'=>$model)); 
} 

와 같은 파일에이 방법을 추가 당신이에 따라 상당히 달라질 수로 리디렉션 무엇

protected function roleBasedHomePage() { 
    $role='theusersrole' //however you define your role, have the value output to this variable 
    switch($role) { 
     case 'admin': 
      $this->redirect(Yii::app()->createUrl('site/page',array('view'=>$role.'homepage')); 
     break; 
     case 'member': 
      $this->redirect(Yii::app()->createUrl('site/page',array('view'=>$role.'homepage')); 
     break; 
     //etc.. 
    } 
} 

무엇 홈 페이지에서 원하는 페이지 유형. 이 경우 정적 페이지를 사용합니다. 페이지의 이름이 일관되게 지정되면 switch 문을 생략하고 createURL 내의 뷰 이름에 역할을 연결할 수 있습니다.

2

당신은 당신이 예를 들어, 사용자 유형에 따라 기본 컨트롤러와 액션에 파일을 볼 변경할 수 있습니다

여기
if($usertype == 'user_type1') { $this->render('usertypeview1'); } 
if($usertype == 'user_type2') { $this->render('usertypeview2'); } 

& usertypeview1 usertypeview2보기 폴더에보기 파일의 이름입니다. 여기

if($usertype == 'user_type1') { $this->layout = 'column1'; } 
if($usertype == 'user_type2') { $this->layout = 'column2'; } 

1 열 및 2 열은 뷰

내가이 도움이되기를 바랍니다 폴더에 배치 폴더 아래의 레이아웃 파일입니다 :

또한 예를 들어 사용자 유형에 따라뿐만 아니라 레이아웃을 변경할 수 있습니다 당신.

관련 문제