Access shell methods in the controller? Cake PHP 1.3

I wrote a wrapper method in CakePHP 1.3 that has a return value.

I would like to access this method from inside the controller so that I can pass its return value to the view.

I am not sure how to access these methods from inside the controller. Did I do it wrong?

I could easily duplicate the code, but I would like to “keep it DRY”, and the actual functionality, I believe, does not belong to this particular controller - I just need to return the value in this particular view.

EDIT:

I understand that I am asking the wrong question here, since the shell itself does not have to return a value. I changed the code so that Shell uses only the return value, and now I'm wondering - what place for additional classes / code should I get from the shell and the Controller?

It looks like component code, but I'm not sure how to access components from the shell. This is not a plugin, as I understand them. Where is it going?

+3
source share
4 answers

In one of the projects, we imported shell tasks, for example:


App::import('Core', 'Shell');
App::Import('Vendor','shells/tasks/sometask');

$returndata = TasknameTask::execute($somevalue);


+5
source

.E.g

/* in app/controllers/components */
class ShellComponent extends Object
{
    function do_shell()
    {
       return shell_exec('some command');
    }
}

, ,

/* in some controller*/
var $components = array('Shell','maybe some other components',....);

function testShell()
{
    $result = $this->Shell->do_shell();
    ....
}
+2

, - , . stdout, , . cli.

, , , - , , . , .

0

, , Cake 2.0

2.0

if (!class_exists('Shell')) {
    require CONSOLE_LIBS . 'shell.php';
}

App::import('Shell', 'DoSomething');
DoSomethingShell::main();

, - Shell, $this- > out, .

0
source

Source: https://habr.com/ru/post/1748048/


All Articles