0

I have an array of behaviour $actas.Problem is when I adding date() function on the array string,it's return an error:

Example:

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' => ''
            )
       )
   );

however it's not working. I also do like this:

 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' => ''
                )
           )
       );

also not worked.

So my question is how to do that? If I have a lot of mistaken,please tell me so I can learn more about the matter.

Thanks in advance.

This is the full source code of Post.php model

<?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()
            )
        )

    );
}
3
  • works for me: codepad.viper-7.com/okEgPw (ignoring the notices) are you sure your showing us the code generating the error Commented Nov 21, 2014 at 23:30
  • it's still not works. keep print out Fatal Error Error: syntax error, unexpected '.', expecting ')' Commented Nov 21, 2014 at 23:36
  • post the full code, the code you posted is not the cause of the error Commented Nov 21, 2014 at 23:37

1 Answer 1

2

ahh ok I was not looking at it with my OO hat on. you can't do this because:

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.

you need to use the __construct() method

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you sir.but I didn't have an idea how to Implement that.If you doesn't mind,can you share some references how to do that,so I can read and do r&d . thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.