'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'index'=>'site/index',
'contact'=>'site/contact',
'signup'=>'site/signup',
'signin'=>'site/signin', // Only this don't work
'signin2'=>'site/signin2',
),
),
.htaccess
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
siteController
<?php
class SiteController extends CController
{
/**
* Declares class-based actions.
*/
public $layout = 'index';
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
// page action renders "static" pages stored under 'protected/views/site/pages'
// They can be accessed via: index.php?r=site/page&view=FileName
'page'=>array(
'class'=>'CViewAction',
),
);
}
/**
* This is the default 'index' action that is invoked
* when an action is not explicitly requested by users.
*/
public function actionIndex()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->render('index');
}
/**
* This is the action to handle external exceptions.
*/
public function actionError()
{
if($error=Yii::app()->errorHandler->error)
{
if(Yii::app()->request->isAjaxRequest)
echo $error['message'];
else
$this->render('error', $error);
}
}
/**
* Displays the contact page
*/
public function actionContact()
{
$this->layout = 'single';
$model=new ContactForm;
if(isset($_POST['ContactForm']))
{
$model->attributes=$_POST['ContactForm'];
if($model->validate())
{
$name='=?UTF-8?B?'.base64_encode($model->name).'?=';
$subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
$headers="From: $name <{$model->email}>\r\n".
"Reply-To: {$model->email}\r\n".
"MIME-Version: 1.0\r\n".
"Content-type: text/plain; charset=UTF-8";
mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
$this->refresh();
}
}
$this->render('contact',array('model'=>$model));
}
/**
* Displays the login page
*/
public function actionLogin()
{
$this->layout = 'single';
$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);
}
// display the login form
$this->render('login',array('model'=>$model));
}
/**
* Logs out the current user and redirect to homepage.
*/
public function actionLogout()
{
Yii::app()->user->logout();
$this->redirect(Yii::app()->homeUrl);
}
/**
* Registering new user
*/
public function actionSignup()
{
$this->layout = 'single';
$model = new NewUser('register');
if(isset($_POST['NewUser']))
{echo 'ccc'.$_POST['NewUser']['username'].'aaa';
$model->attributes = $_POST['NewUser'];
if($model->validate())
if($model->save()){
$url = Yii::app()->createAbsoluteUrl('verify');
send_verify_code($url,$model->verify_string,null,$model->email);
}
}
$this->render('register',array('model'=>$model));
}
public function actionSignin()
{
}
}
Didn’t work! In this way user will be direct to website/index.php/site/signin, i want user only can obtain website/index.php/site/signin through website/index.php/signin and not accessible website/index.php/site/signin for user. Throw out a exception like 404 to user when it requests the website/index.php/site/signin.
browser redirect to a white page without any content! I want when user requests the site/singin URL a 404 error throw out ahead the user, how can do it?
i currently use following solution:
'signin'=>'site/signin'
'site/signin'=>'signin' //signin route not exist so throw out a 404 error.
Dear @KonApaz, your posts(and other friends) are useful, so votes are minimum thing also Vote button is for to use At last i think your last post is my answer, very thanks again.
I used following code for obtain the requested action:
public function actionNoPage() {
$actionPos = strrpos(Yii::app()->request->url,'/');
$actionId = substr(Yii::app()->request->url,$actionPos+1);
throw new CHttpException(404,Yii::t('yii','The system is unable to find the requested action "{action}".',array("{action}"=>$actionId)));
}
$action = Yii::app()->getController()->getAction()->getId() or $this->getAction()->getId()
$id = Yii::app()->getRequest()->getQuery('id');
throw new CHttpException(404,Yii::t('yii','The system is unable to find the requested action "{$action}/{$id}");
ok, comments the actionNopage method in your Site Controller. the site/signin will be routed to site/nopage tha is not exists. So errorHandler action catch the exception (actionError() in site Controller) and automatically displays which of controller/action is not exist.