2014-11-21 11 views
0

我有行爲$ actas.Problem的陣列,當我在陣列字符串添加日期()函數,它返回一個錯誤:加入PHP函數在CakePHP的模型排列

例子:

public $actas = array(
'Uploader.Attachment'=>array( 
     'books' => array(
      'maxWidth' => 1200, 
      'maxHeight' => 1200, 
      'extension' => array('pdf'), 
      'nameCallback' => '', 
      'append' => '', 
      'prepend' => '', 
      'tempDir' => TMP, 
      'uploadDir' => '/var/www/html/apps/webroot/files/uploads/books' . date('d-m-Y'),//this is where I want to add the function. 
      'transportDir' => '' 
      ) 
     ) 
    ); 

但是它不起作用。我也這樣做:

public $actas = array(
    'Uploader.Attachment'=>array( 
      'books' => array(
       'maxWidth' => 1200, 
       'maxHeight' => 1200, 
       'extension' => array('pdf'), 
       'nameCallback' => '', 
       'append' => '', 
       'prepend' => '', 
       'tempDir' => TMP, 
       'uploadDir' => "/var/www/html/apps/webroot/files/uploads/books'".date('d-m-Y')."'",//this is where I want to add the function. 
       'transportDir' => '' 
       ) 
      ) 
     ); 

也沒有工作。

所以我的問題是如何做到這一點?如果我有很多錯誤,請告訴我,以便我可以瞭解有關此事的更多信息。

在此先感謝。

這是post.php中模型

<?php 
App::uses('AppModel', 'Model'); 
/** 
* Post Model 
* 
* @property Tier $Tier 
* @property Category $Category 
* @property Comment $Comment 
*/ 
class Post extends AppModel { 
     //var $now = 'CURDATE()'; 
/** 
* Validation rules 
* 
* @var array 
*/ 
    public $validate = array(
     'title' => array(
      'notEmpty' => array(
       'rule' => array('notEmpty'), 
       //'message' => 'Your custom message here', 
       //'allowEmpty' => false, 
       //'required' => false, 
       //'last' => false, // Stop validation after this rule 
       //'on' => 'create', // Limit validation to 'create' or 'update' operations 
      ), 
     ), 
     'content' => array(
      'notEmpty' => array(
       'rule' => array('notEmpty'), 
       //'message' => 'Your custom message here', 
       //'allowEmpty' => false, 
       //'required' => false, 
       //'last' => false, // Stop validation after this rule 
       //'on' => 'create', // Limit validation to 'create' or 'update' operations 
      ), 
     ), 

    ); 

    //The Associations below have been created with all possible keys, those that are not needed can be removed 

/** 
* belongsTo associations 
* 
* @var array 
*/ 
    public $belongsTo = array(
     'Tier' => array(
      'className' => 'Tier', 
      'foreignKey' => 'tier_id', 
      'conditions' => '', 
      'fields' => '', 
      'order' => '' 
     ), 
     'Category' => array(
      'className' => 'Category', 
      'foreignKey' => 'category_id', 
      'conditions' => '', 
      'fields' => '', 
      'order' => '' 
     ) 
    ); 

/** 
* hasMany associations 
* 
* @var array 
*/ 
    public $hasMany = array(
     'Comment' => array(
      'className' => 'Comment', 
      'foreignKey' => 'post_id', 
      'dependent' => false, 
      'conditions' => '', 
      'fields' => '', 
      'order' => '', 
      'limit' => '', 
      'offset' => '', 
      'exclusive' => '', 
      'finderQuery' => '', 
      'counterQuery' => '' 
     ) 
    ); 

    public $actsAs = array(
    //'Containable', 
    'Uploader.Attachment' => array(
     // Do not copy all these settings, it's merely an example 
     'banner' => array(
      'maxWidth' => 1200, 
      'maxHeight' => 1200, 
      'extension' => array('gif', 'jpg', 'png', 'jpeg'), 
      'nameCallback' => '', 
      'append' => '', 
      'prepend' => '', 
      'tempDir' => TMP, 
      'uploadDir' => "/var/www/html/apps/webroot/img/banners/", 
      'transportDir' => '', 
      'finalPath' => '/img/banners/', 
      'dbColumn' => '', 
      'metaColumns' => array(), 
      'defaultPath' => '', 
      'overwrite' => true, 
      'transforms' => array(), 
      'stopSave' => true, 
      'allowEmpty' => true, 
      'transformers' => array(), 
      'transport' => array(), 
      'transporters' => array(), 
      'curl' => array() 
      ), 
     'feature' => array(
      'maxWidth' => 1200, 
      'maxHeight' => 1200, 
      'extension' => array('gif', 'jpg', 'png', 'jpeg'), 
      'nameCallback' => '', 
      'append' => '', 
      'prepend' => '', 
      'tempDir' => TMP, 
      'uploadDir' => '/var/www/html/apps/webroot/img/features/', 
      'transportDir' => '', 
      'finalPath' => '/img/features/', 
      'dbColumn' => '', 
      'metaColumns' => array(), 
      'defaultPath' => '', 
      'overwrite' => true, 
      'transforms' => array(), 
      'stopSave' => true, 
      'allowEmpty' => true, 
      'transformers' => array(), 
      'transport' => array(), 
      'transporters' => array(), 
      'curl' => array() 
      ), 
    'books' => array(
      'maxWidth' => 1200, 
      'maxHeight' => 1200, 
      'extension' => array('pdf'), 
      'nameCallback' => '', 
      'append' => '', 
      'prepend' => '', 
      'tempDir' => TMP, 
      'uploadDir' => '/var/www/html/apps/webroot/files/uploads/books' . date('d-m-Y'), 
      'transportDir' => '', 
      'finalPath' => '/files/uploads/books/', 
      'dbColumn' => '', 
      'metaColumns' => array(), 
      'defaultPath' => '', 
      'overwrite' => true, 
      'transforms' => array(), 
      'stopSave' => true, 
      'allowEmpty' => true, 
      'transformers' => array(), 
      'transport' => array(), 
      'transporters' => array(), 
      'curl' => array() 
      ) 
     ) 

    ); 
} 
+0

作品對我來說:http://codepad.viper-7.com/okEgPw(忽略通知)您是否確定,因爲你不能做到這一點您向我們展示的代碼生成錯誤 – 2014-11-21 23:30:21

+0

它仍然無法正常工作。保持打印輸出 致命錯誤 錯誤:語法錯誤,意外的'。',期待')' – 2014-11-21 23:36:52

+0

發佈* full *代碼,您發佈的代碼不是錯誤原因 – 2014-11-21 23:37:50

回答

2

啊好,我沒有與我的OO帽子看着它的全部源代碼。

Properties 

Class member variables are called "properties". You may also see them referred to using other terms such as "attributes" or "fields", but for the purposes of this reference we will use "properties". They are defined by using one of the keywords public, protected, or private, followed by a normal variable declaration. This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

您需要使用__construct()方法

+0

謝謝先生。但我沒有想法如何實現這一點。如果你不介意,你可以分享一些參考文獻怎麼做,所以我可以閱讀和做研發。再次感謝。 – 2014-11-22 00:45:39