Skip to content

Commit 3a9bcff

Browse files
committed
_JsUtils CakePHP terminated
1 parent 73aa8ef commit 3a9bcff

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

Ajax/php/cakephp/_JsUtils.php

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
namespace Ajax\php\cakephp;
44

55

6-
use Ajax\service\JString;
76
use Cake\Routing\Router;
7+
use Cake\View\View;
8+
use Cake\Network\Response;
9+
use Cake\Core\App;
10+
811
class _JsUtils extends \Ajax\JsUtils{
912
public function getUrl($url){
1013
return Router::url($url);
@@ -25,32 +28,39 @@ public function createScriptVariable(&$view,$view_var, $output){
2528
}
2629

2730
/**
28-
* @param Symfony\Component\DependencyInjection\ContainerInterface $initialControllerInstance
31+
* @param App\Controller\AppController $initialControllerInstance
2932
* @param string $controllerName
3033
* @param string $actionName
3134
* @param array $params
3235
* @see \Ajax\JsUtils::forward()
3336
*/
3437
public function forward($initialControllerInstance,$controllerName,$actionName,$params=array()){
35-
$path=$params;
36-
$request = $initialControllerInstance->get('request_stack')->getCurrentRequest();
37-
$path['_forwarded'] = $request->attributes;
38-
$path['_controller'] = $controllerName.":".$actionName;
39-
$subRequest = $request->duplicate([], null, $path);
40-
$response= $initialControllerInstance->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
41-
return $response->getContent();
38+
\ob_start();
39+
if(isset($params) && \is_array($params)===false){
40+
$params=[$params];
41+
}
42+
$url=h(Router::url(\array_merge([
43+
'controller' => $controllerName,
44+
'action' => $actionName],$params),false
45+
));
46+
$base=Router::url("/");
47+
if (substr($url, 0, strlen($base)) == $base) {
48+
$url = substr($url, strlen($base));
49+
}
50+
$initialControllerInstance->requestAction($url);
51+
$result=\ob_get_contents();
52+
\ob_end_clean();
53+
return $result;
4254
}
4355

4456
public function renderContent($initialControllerInstance,$viewName, $params=NULL) {
45-
if ($initialControllerInstance->has('templating')) {
46-
return $initialControllerInstance->get('templating')->render($viewName, $params);
47-
}
48-
49-
if (!$initialControllerInstance->has('twig')) {
50-
throw new \LogicException('You can not use the "renderView" method if the Templating Component or the Twig Bundle are not available.');
51-
}
52-
53-
return $initialControllerInstance->get('twig')->render($viewName, $params);
57+
$view = new View(Router::getRequest(true), new Response());
58+
if(\is_array($params)){
59+
foreach ($params as $k=>$v){
60+
$view->set($k, $v);
61+
}
62+
}
63+
return $view->render($viewName);
5464
}
5565

5666
public function fromDispatcher($dispatcher){

0 commit comments

Comments
 (0)