其中var是我的代碼:CakePHP的分配從功能/法
class ManImportsController extends AppController {
public $uppath;
var $name = 'ManImports';
var $uses = array ('RFupload','ManImport');
var $helpers = array ('Html', 'Session','Time', 'Form', 'Js', 'Javascript','DatePicker','Ajax','IrDependentArray','databaseFields','FileUpload.FileUpload', 'showFields');
var $components = array ('FileUpload.FileUpload','Session','RequestHandler');
var $actsAs = array('FileUpload.FileUpload' => array(
'uploadDir' => $this->uppath, // Primary Upload Path
'forceWebroot' => false, // false, files upload to uploadDir
'fields' => array ('name' => 'name', 'size' => 'size',
'date' => 'date', 'created' => 'created',
'type' => 'type'),
'allowedTypes' => array ('csv' => array('application/csv'),
'xls' =>array('application/vnd.ms-excel'),
'xlsx' =>array('application/vnd.ms-excel')),
'required' => false, // true = errors when file isn't uploaded.
'maxFileSize' => false, // false to turns off maxFileSize
'unique' => true, // true will overwrite files with same name.
'massSave' => true,
'fileNameFunction' => false)); //execute the Sha1 function on a filename before saving it (default false)
public function beforeFilter() {
$this->uppath = $this->get_path();
} // end function beforeFilter
function get_path() {
$mach = gethostname();
if ($mach=='my_machine_ID') {
$path = "C:/home/files/uploads/";
} else {
$path = '/home/files/uploads/';
} // end if $mach
return $path;
} // end function get_path
} // end class ManImportsController
問題是讓「uploadDir」通過適當調用函數/法「get_path」正確分配。我已經嘗試了4種不同的組合,從cakePHP約定和PHP OOP,但到目前爲止還沒有工作。
你看到我在這裏錯過了什麼,你能告訴我正確的方式來稱呼它!
我必須在Linux上部署,但需要與Win7開發機器一起工作。
你有什麼錯誤嗎?我不確定它是否與您的問題有關,但行爲是在模型中定義的,而不是在控制器中定義的。 – dhofstet