2017-04-01 34 views
0

我想要將文件上傳到文件夾,並將其名稱從Temp.ctp提交到Temp數據庫的tbl_temps表。我已經通過模型文件夾中的名稱創建了模型。但我收到以下內容錯誤:無法找到TempsController.Cake PHP

錯誤:無法找到TempsController.Cake PHP。

錯誤:在文件中創建以下類TempsController:應用程序\控制器\ 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

錯誤消息是很清楚你應該做什麼:
錯誤:在文件中創建類TempsController:app \ Co ntroller \ TempsController.php

你應該先了解Model-View-Controller principle,然後移動到你的Temp模型創建Controller

你必須創建一個文件​​:

<?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 
    } 
}