View getRender($controller,$action,$params,-->$callback<-- )

Hello, why $callback can use only anonymous function?
callback must support various ways(because he is callback :) ), like ['class','method'], plain function name. Now only works anonymous function.

<?php
// now it works!
function getTemplate($controller, $action, $params = [], $callback = null) {
        $inner = null;
        if (is_callable($callback)) {
            $inner = function (\Phalcon\Mvc\View $view) use ($callback) {
                call_user_func_array($callback, [$view]);
            };
        }
        return $this->view->getRender($controller, $action, $params, $inner);
    }


2.2k
edited Apr '19

public string getRender (string $controllerName, string $actionName, [array $params], [mixed $configCallback])

View::getRender() can accept only closure so you can skip the is_callable() check

function getTemplate($controller, $action, $params = [], $callback = null) {
    return $this->view->getRender($controller, $action, $params, $callback);
}


1.1k
<?php
function thisFunctionNeverCallingOnGetRender(\Phalcon\Mvc\View $view) {
   die('NEVER');
    $view->setRenderLevel(\Engine\Mvc\View::LEVEL_LAYOUT);
}
//not work
$this->view->getRender($controller, $action, $params, 'thisFunctionNeverCallingOnGetRender');

but works on my first comment. callback must work various ways or only closure?

public string getRender (string $controllerName, string $actionName, [array $params], [mixed $configCallback])

View::getRender() can accept closure/object so you can skip the is_callable() check

function getTemplate($controller, $action, $params = [], $callback = null) {
   return $this->view->getRender($controller, $action, $params, $callback);
}


2.2k
edited Apr '19

i just relized that it must be a closure

sorry about that

$configCallback must be a closure

Source Code

https://github.com/phalcon/cphalcon/blob/3.4.x/phalcon/mvc/view.zep

if typeof configCallback == "object" {
    call_user_func_array(configCallback, [view]);
}

$callback = function (View $view) {
    // callback stuff
};

$this->view->getRender($controller, $action, $params, $callback);