在Shell中工作时,我遇到了基本路径全局变量的问题。例如,在shell中加载我的File模型时,'APP'常量不可用,导致该行:
$fileStorePath = APP.'/Data/FileStore/';
要生成以下错误:
PHP Parse error: syntax error, unexpected '.', expecting ',' or ';' in
/home/cakedev/public_html/app/Model/File.php on line 15
我错过了一些基本的东西吗?这不像我正在尝试使用apache环境变量......我只需要APP全局。
这是File.php
<?php
App::uses('AppModel', 'Model');
/**
* File model
*
* Store files and retrieve them
*
*/
class File extends AppModel {
public $displayField = 'filename';
public $actsAs = array('Logable','Error');
private $__fileStorePath = APP.'/Data/FileStore/';
function beforeSave($options = array()) {
// Make sure input file exists
if ( !file_exists($this->data['File']['inputfile']) ) {
$this->throwError(__('File [%s] does not exist',$this->data['File']['inputfile']));
return;
}
// Tack on the file info
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$this->data['File']['filename'] = basename($this->data['File']['inputfile']);
$this->data['File']['mime'] = finfo_file($finfo, $this->data['File']['inputfile']);
$this->data['File']['size'] = filesize($this->data['File']['inputfile']);
$this->data['File']['uuid'] = uniqid();
return true;
}
function afterSave($created) {
if ( $created ) {
// Move the file
if ( !rename($this->data['File']['inputfile'],$this->__fileStorePath.$this->data['File']['uuid']) ) {
$this->throwError(__('File [%s] could not be moved',$this->data['File']['input']),500);
return;
}
}
return true;
}
var $belongsTo = array(
'User' => array('className' => 'User',
'foreignKey' => 'user_id',
)
);
}
答案 0 :(得分:0)
嗯,我是一个白痴......你不能在课堂定义中连接。这是一个PHP&#39;功能&#39;不是蛋糕虫。蛋糕很好......