我在yii框架中创建了一个webapp。它在本地主机上工作得很好但是当我在服务器上部署它时会抛出错误:
Error 404
Unable to resolve the request "ActionName".
我检查了所有配置文件的所有URL和路径,但无法找到任何解决方案。即使我从我的根目录中删除.htaccess文件但没有解决方案:( 任何人都可以帮我解决它。
我的main.php代码是:
<?php
return array(
'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
'preload' => array('log'),
// autoloading model and component classes
'import' => array(
'application.models.*',
'application.components.*',
'ext.giix.components.*', // giix components
),
'modules' => array(
// uncomment the following to enable the Gii tool
'gii' => array(
'class' => 'system.gii.GiiModule',
'password' => 'jar',
'generatorPaths' => array(
'ext.giix.core', // giix generators
),
),
),
// application components
'components' => array(
'user' => array(
// enable cookie-based authentication
'allowAutoLogin' => true,
),
'ePdf' => array(
'class' => 'ext.yii-pdf.EYiiPdf',
'params' => array(
'HTML2PDF' => array(
'librarySourcePath' => 'application.vendors.html2pdf.*',
'classFile' => 'html2pdf.class.php', // For adding to Yii::$classMap
)
),
),
'session' => array(
'timeout' => 300,
'cookieMode' => 'only',
'cookieParams' => array('secure' => false, 'httponly' => false),
),
'db' => array(
'connectionString' => 'mysql:host=localhost;dbname=nameofdb',
'emulatePrepare' => true,
'username' => 'UN',
'password' => 'pass',
'charset' => 'utf8',
),
'errorHandler' => array(
// use 'site/error' action to display errors
'errorAction' => 'site/error',
),
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
array(
'class' => 'CFileLogRoute',
'levels' => 'error, warning',
),
),
),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params' => array(
// this is used in contact page
'adminEmail' => 'xyz@abc.com',
),
);
我的控制器代码如下: districtController.php
class districtController extends Controller {
/**
* Declares class-based actions.
*/
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'
); }
public function actionIndex() {
$this->render('index');
}
public function actionSda() {
$this->render('sda');
}
public function actionIqt() {
$this->render('iqt');
}
public function actionSm() {
$this->render('sm');
}
public function actionCreate() {
$model = new SchoolDetails;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['SchoolDetails'])) {
$model->attributes = $_POST['SchoolDetails'];
$model->setAttribute('school_doc', date('y:m:d, h:m:s'));
if ($model->save())
$this->redirect(array('view', 'id' => $model->school_id));
}
$this->render('create', array(
'model' => $model,
));
}
public function actionUpdate($id) {
$model = $this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['SchoolDetails'])) {
$model->attributes = $_POST['SchoolDetails'];
if ($model->save())
$this->redirect(array('view', 'id' => $model->school_id));
}
$this->render('update', array(
'model' => $model,
));
}
public function actionView($id) {
$this->render('view', array(
'model' => $this->loadModel($id),
));
}
public function actionDelete($id) {
$this->loadModel($id)->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if (!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
public function actionAdmin() {
$model = new SchoolDetails('search');
$model->unsetAttributes(); // clear any default values
if (isset($_GET['SchoolDetails']))
$model->attributes = $_GET['SchoolDetails'];
$this->render('admin', array(
'model' => $model,
));
}
public function loadModel($id) {
$model = SchoolDetails::model()->findByAttributes(array('school_id' => $id));
if ($model === null)
throw new CHttpException(404, 'The requested page does not exist.');
return $model;
}
/* School Operations page actions Ends */
public function actionStudent_create() {
$model = new StudentDetails;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['StudentDetails'])) {
$school = SchoolDetails::model()->findByAttributes(array('school_name' => $_POST['StudentDetails']['student_school_name']));
$model->attributes = $_POST['StudentDetails'];
$model->setAttribute('student_doc', date('y:m:d, h:m:s'));
$model->setAttribute('school_id', $school->school_id);
if ($model->save())
$this->redirect(array('view', 'id' => $model->student_id));
}
$this->render('student_create', array(
'model' => $model,
));
}
public function actionUpdate_student($id) {
$model = $this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['StudentDetails'])) {
$school = SchoolDetails::model()->findByAttributes(array('school_name' => $_POST['StudentDetails']['student_school_name']));
$model->attributes = $_POST['StudentDetails'];
$model->setAttribute('student_doc', date('y:m:d, h:m:s'));
$model->setAttribute('school_id', $school->school_id);
if ($model->save())
$this->redirect(array('view', 'id' => $model->student_id));
}
$this->render('update_student', array(
'model' => $model,
));
}
public function actionView_student($id) {
$this->render('view_student', array(
'model' => $this->loadModel_Student($id),
));
}
public function loadModel_Student($id) {
$model = StudentDetails::model()->findByPk($id);
if ($model === null)
throw new CHttpException(404, 'The requested page does not exist.');
return $model;
}
protected function performAjaxValidation($model) {
if (isset($_POST['ajax']) && $_POST['ajax'] === 'lahaulandspiti-school-details-form') {
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
/**
* 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);
}
}
}
当我打 http://example.com/abc_new/index.php?r=district&districtId=1 或任何其他内部网址。我得到了同样的错误。
请帮助我解决这个问题。