错误:无法找到TempsController。请使用PHP

时间:2017-04-01 10:00:48

标签: cakephp

我希望将文件上传到files文件夹,并将它们的名称从temp.ctp提交到Temp数据库的tbl_temps表。我在模型文件夹中创建了名为Temp的模型。但我收到了以下

错误:无法找到TempsController。请使用PHP。

错误:在文件中创建下面的TempsController类:app \ Controller \ TempsController.php

temp.ctp

<?php
echo $this->Form->Create("Temp",array("action"=>"temp","enctype"=>"multipart/form-data"));
echo $this->Form->input("file.",array("label"=>false,"div"=>false,"type"=>"file"));
echo $this->Form->input("file.",array("label"=>false,"div"=>false,"type"=>"file"));
?>
<input type="submit"/>
<?php   
echo $this->Form->end();
?>

PagesController

<?php

App::uses('AppController', 'Controller');


public $uses = array("Temp");


public function temp(){

    if($this->request->is("post")){
        $uploaded_files="";
        foreach($this->data["Temp"]["file"] as $file1){
            $ret_value = $this->PImage->upload($file1,'/app/webroot/files');
            if (isset($ret_value[1]) && !empty($ret_value[1])) {
                                $msgString .= "- File not valid.<br>";
                            } 
            else {
                if($uploaded_files){
                    $uploaded_files.= ",*".$ret_value[0];
                }
                else{
                    $uploaded_files=$ret_value[0];
                }
            }
        }
        $this->request->data["Temp"]["file"]=$uploaded_files;
        $this->Temp->save($this->data);
    }
}
}

1 个答案:

答案 0 :(得分:1)

错误信息非常清楚你应该做什么:
错误:在文件中创建下面的TempsController类:app \ Controller \ TempsController.php

您应首先了解Model-View-Controller principle,然后继续为Temp模型创建Controller

您必须创建文件/app/Controller/TempsController.php

<?php
App::uses('AppController', 'Controller');

class TempsController extends AppController {

    /* this action will be accessible at '/temps/index' with default routing */

    public function index() {
        // do stuff here
    }
}