0

I want to use a form variable inside a cakephp model class variable $actsAs.Below is an example code.

public $actsAs = array('MeioUpload' => array('doc' => array('allowedMime' => array('application/x-compressed','application/x-zip-compressed','application/zip','multipart/x-zip'),'dir'=>'uploads'.DS.$this->data['User']['foldername'])));

In the above code i have used a form variable ($this->data['User']['foldername']) in the $actsAs array for passing directory name to meioupload behaviour.

What can be the write process to implement it.

3 Answers 3

1

That definition is wrong.

You can set that data from the constructor though.

public function __construct($data) {
    $this->actsAs = array('MeioUpload' => array('doc' => array('allowedMime' => array('application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip'), 'dir' => 'uploads' . DS . $data['User']['foldername'])));
}

Something like that would do the trick.

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

Comments

0

I added parent::__construct(); And $this->Behaviors->init($this->alias,$this->actsAs); and it works good.

Below is the modified code:

public function  __construct() {        
    parent::__construct();

    $this->actsAs = array('MeioUpload' => array('doc' => array('allowedMime' => array('application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip'), 'allowedExt' => array('.zip'),'dir' => 'uploads' . DS . $_REQUEST['data']['User']['foldername'])));

    $this->Behaviors->init($this->alias,$this->actsAs);         
}

Comments

0

In this example I’m changing path dynamically from controller.

CODE :

In Controller ( Where you specifying data to change value of $actsAs variable ) :

$custom_path=’/img/cakephp’;
Configure::write(‘path_var’,$custom_path);

In Model where you’ll change value in constructor :

public function __construct($id = false, $table = null, $ds = null)
{
  $path = Configure::read(‘path_var’);
  // change actsAs’s different value according to your need
  $this->actsAs['Upload.Upload']['photo']['path'] = $path;
  parent::__construct($id, $table, $ds);
}

Please write statement Configure::write before model created.

Comments

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.