Required Login

Below are code snippets I am using. It works great but I want to allow access to one more page that is located under /site/pages/news.php. I attempted to add it to the array several different ways but I am stillb being forced to login on this page.

***config main.php

‘behaviors’ => array(

'onBeginRequest' => array(


    'class' => 'application.components.RequireLogin'


)


),

***requirelogin.php

class RequireLogin extends CBehavior

{

public function attach($owner)


{


	$owner->attachEventHandler('onBeginRequest', array($this, 'handleBeginRequest'));


}





public function handleBeginRequest($event)


{    	


	


	$app = Yii::app();


	$user = $app->user;		 





	$request = trim($app->urlManager->parseUrl($app->request), '/');


	$login = trim($user->loginUrl[0], '/');





	// Restrict guests to public pages.


	$allowed = array($login,'site/index','site/contact');


	if ($user->isGuest && !in_array($request, $allowed))


	$user->loginRequired();





	 // Prevent logged in users from viewing the login page.


	 $request = substr($request, 0, strlen($login));


	 if (!$user->isGuest && $request == $login)


	 {


		 $url = $app->createUrl($app->homeUrl[0]);


		 $app->request->redirect($url);


	 }


}

}

Dear Friend

To simulate your scenario, this is the working code in my localhost.

components/ApplicationBehavior.php




class ApplicationBehavior extends CBehavior

{

    public function events()

    {

        return array(

            'onBeginRequest'=>'restrict'

        );

    }

    

    public function restrict()

    {   $owner=$this->owner;

        $routes=array(

            array("site/index",array()),

            array('site/contact',array()),

            array("site/page",array('view'=>'news')), //included "index.php?r=site/page&view=news"

                    );

        $allowed=array();

        foreach($routes as $route)

            $allowed[]=$owner->createUrl($route[0],$route[1]);


        if($owner->user->isGuest && !in_array($owner->request->url,$allowed))

            $owner->catchAllRequest=array('site/login');


        if(!$owner->user->isGuest && $owner->request->url==$owner->createUrl('site/login'))

            throw new CHttpException(" :You have already logged in");//Throwing error is not a good option though.

    }

}



Attach this behavior in main.php




'behaviors'=>array(

    'appBehav'=>'ApplicationBehavior',    

    ),



Regards.