0

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

2 Answers 2

1

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()
Sign up to request clarification or add additional context in comments.

Comments

0

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.

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.