Wednesday, 15 February 2012

php - CakePHP How to call a controller function from an external function -



php - CakePHP How to call a controller function from an external function -

i'm having problem accessing session in external .php script located in webroot.

thought i'd write function getsession() in 1 of controllers , seek phone call in .php file.

so in steps:

i have file.php in controller have function getsession(). how phone call controllers function in file.php?

thank you.

edit

meanwhile fixed bug, still curious how done , want other stack users find reply so:

its this:

in userscontroller have function:

public function getsession() { homecoming $_session['auth']['user']['user_id']; }

that want let's print (for example) this: print_r(users.getsession) in file test.php located in webroot/uploadify/test.php.

this file not class, if required, shall :)

@caboone: maybe reply correct, wasnt sure code phone call (and enter) :)

supposed have next php file in webroot folder:

<?php class testingclass { function getname(){ homecoming "test"; } } ?>

i following:

// bring /webroot folder include $_server['document_root'].'/another_file.php'; // initializing class $example = new testingclass; // phone call function initialized class $a_value = $example->getname(); // if want utilize $a_value in view, can set $this->set('a_value', $a_value);

php cakephp-2.1

No comments:

Post a Comment