i have a component class

class ChimagesUploadComponent extends Object{

/***************************** * fileModel is the name of the model used if we want to * keep records of uploads in a database. * * if you don't wish to use a database, simply set this to null * $this->FileUpload->fileModel = null; * * @var mixed * @access public */

var $fileModel = 'Image';

/***************************** * uploadDir is the directory name in the webroot that you want * the uploaded files saved to. default: files which means * webroot/files must exist and set to chmod 777 * * @var string * @access public */

var $uploadDir = 'chimages';

and function in app_controller

function getCurrentUser() {

App::import('Component','Session'); $Session = new SessionComponent();

$user = $Session->read('Auth.User');

return $user; }

i want to use this function in my class ChimagesUploadComponent.

the reason is i want to save the images in different folder retrieving the folder name from the function and saving it accordingly i tried with concatinating

in class ChimagesUploadComponent. i did

 $user=$this->getCurrentUser();
$logid = $user['district_id'];

and then tried to concatenate it in

var $uploadDir = 'chimages/'.$logid;

as i have different folders in webroot/chimages/12 webroot/chimages/13 etc. please help

有帮助吗?

解决方案

It is better to pass value in argument during the calling of component from controller.

But if you still want to access the Application Controller method then just call using

AppController::getCurrentUser()

其他提示

The following may be the another way to do this is

$Appcontroller= new AppController();
$Appcontroller->calltoanyfunction();

And in this way you can call any controller's function into another one.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top