控制器无法找到请求的视图Yii错误


Controller can't find requested view Yii error

我正在做Yii项目。它的在我的本地主机上完美地工作。当我在服务器上上传项目时,我是在产品csv上传页面上的服务器上得到错误,它给我错误为

ImportcsvController找不到请求的view "import"。

我有Importcsv控制器文件,Importcsv文件夹(包含import.php和Importcsv .php)在视图文件夹和Importcsv模型文件。一切都很好在本地主机,但我不明白为什么它给我错误的服务器。所有文件都上传的很好。

My Controller is

<?php
class ImportcsvController extends Controller
{
/**
 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
 * using two-column layout. See 'protected/views/layouts/column2.php'.
 */
public $layout='//layouts/main';
public $defaultAction='import';
/**
 * @return array action filters
 */
public function filters()
{
    return array(
        'accessControl', // perform access control for CRUD operations
        'postOnly + delete', // we only allow deletion via POST request
    );
}
/**
 * Specifies the access control rules.
 * This method is used by the 'accessControl' filter.
 * @return array access control rules
 */
public function accessRules()
{
    return array(
        array('allow',  // allow all users to perform 'index' and 'view' actions
            'actions'=>array('view','import'),
            'users'=>array('*'),
        ),
    );
}
/**
 * Displays a particular model.
 * @param integer $id the ID of the model to be displayed
 */
public function actionView($id)
{
    $this->render('view',array(
        'model'=>$this->loadModel($id),
    ));
}

    public function actionImport() {
        $model = new Importcsv;
        $file = CUploadedFile::getInstance($model,'csv_file');
        if(isset($_POST['Importcsv']))
        {
            $model->attributes=$_POST['Importcsv'];
            if(!empty($_FILES['Importcsv']['tmp_name']['csv_file']))
            {
                $file = CUploadedFile::getInstance($model,'csv_file');

                $fp = fopen($file->tempName, 'r');
                if($fp)
                {
                     $line = fgetcsv($fp, 1000, ",");
                    $first_time = true;

                                            //begin transaction
                                            $transaction=Yii::app()->db->beginTransaction();
                                        try {

                                            //truncate table before importing csv
                                            Yii::app()->db->createCommand("truncate table products")->execute();

                                            //add csv ecords
                                                        do {
                                                                if ($first_time == true) {
                                                                        $first_time = false;
                                                                        continue;
                                                                }
                                                                $model = new Products;
                                                                $model->product_name  = $line[1];
                                                                $model->product_code  = $line[2];
                                                                $model->price  = $line[3];
                                                                $model->mrp  = $line[4];
                                                                $model->quantity  = $line[5];
                                                                if($line[6]==''){ 
                                                                        $model->image  = 'noimage.jpg';
                                                                }
                                                                else {
                                                                        $model->image  = $line[6];
                                                                }
                                                                $model->status  = $line[7];
                                                                $model->created_at  = date('Y-m-d h:i:s');
                                                                $model->save();
                                                        }while( ($line = fgetcsv($fp, 1000, ",")) != FALSE);
                                            $transaction->commit();
                                             } catch (Exception $e) {
                                            $transaction->rollback();
                                             }

                                    }
            }
            $this->redirect(array("Products/index"));
        }

        $this->render('import', array('model' => $model) );
    }

/**
 * Performs the AJAX validation.
 * @param Company $model the model to be validated
 */
protected function performAjaxValidation($model)
{
    if(isset($_POST['ajax']) && $_POST['ajax']==='importcsv-form')
    {
        echo CActiveForm::validate($model);
        Yii::app()->end();
    }
}
}
?>

我的视图是(import.php)

<?php
 // var_dump($model);
 $this->renderPartial('importcsv', array('model'=>$model)); 
?>

importcsv.php是

<div class="form">


<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'importcsv-form',
'enableAjaxValidation'=>true,
'type' => 'horizontal',
'htmlOptions' => array('enctype'=>'multipart/form-data', 'class'=>'col-sm-offset-   2'),
));

?>

<fieldset>
    <legend>
        <p class="note">Fields with <span class="required">*</span> are required.</p>
    </legend>


    <div class="control-group">     
        <div class="span4">
                <?php echo $form->labelEx($model,'csv_file'); ?> 
                <?php echo $form->fileField($model,'csv_file'); ?> 
                <?php echo $form->error($model, 'csv_file'); ?>
        </div>
    </div>

    <div class="row buttons  col-sm-offset-2">
        <?php echo CHtml::submitButton('Upload CSV',array("class"=>"btn btn-primary")); ?> <?php echo $form->errorSummary($model); ?>
    </div>
</fieldset>

<?php $this->endWidget(); ?>

My Model is(importcsv.php)

<?php
class Importcsv extends CFormModel
{
public $csv_file;
/**
 * @return array validation rules for model attributes.
 */
public function rules() { 
        return array( array('csv_file', 'file', 'types' => 'csv' ,
            'maxSize'=>5242880, 
            'allowEmpty' => true, 
            'wrongType'=>'Only csv allowed.', 
            'tooLarge'=>'File too large! 5MB is the limit'
            )
            );  

} 
public function attributeLabels() { 
        return array('csv_file'=>'Import CSV',); 
}
}
?>

我不知道我哪里错了…请帮助我,提前感谢....

在protected/views中创建的目录的第一个字母不能以大写字母开头(在Linux系统上是这样)。

如果您的主机服务是Linux,那么请检查文件夹名称,这可能会对您有所帮助。祝一切顺利