Skip to content

Commit fc9cadf

Browse files
committed
Cakephp started
1 parent bc53b5d commit fc9cadf

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

Ajax/php/cakephp/JsUtilsComponent.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
4+
use Ajax\php\cakephp\_JsUtils;
5+
use Cake\Controller\Component;
6+
use Ajax\Semantic;
7+
8+
class JsUtilsComponent extends Component {
9+
/**
10+
* @var Ajax\php\cakephp\_JsUtils
11+
*/
12+
public $jquery;
13+
\extract($config);
14+
$this->jquery=new _JsUtils();
15+
if(isset($semantic)){
16+
$this->jquery->semantic(new Semantic());
17+
}
18+
}
19+
}

Ajax/php/cakephp/_JsUtils.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Ajax\php\cakephp;
4+
5+
6+
use Ajax\service\JString;
7+
use Cake\Routing\Router;
8+
class _JsUtils extends \Ajax\JsUtils{
9+
public function getUrl($url){
10+
return Router::url($url);
11+
}
12+
public function addViewElement($identifier,$content,&$view){
13+
$viewVars=$view->viewVars;
14+
if (isset($viewVars["q"]) === false) {
15+
$controls=array ();
16+
}else{
17+
$controls=$viewVars["q"];
18+
}
19+
$controls[$identifier]=$content;
20+
$view->set("q", $controls);
21+
}
22+
23+
public function createScriptVariable(&$view,$view_var, $output){
24+
$view->set($view_var,$output);
25+
}
26+
27+
/**
28+
* @param Symfony\Component\DependencyInjection\ContainerInterface $initialControllerInstance
29+
* @param string $controllerName
30+
* @param string $actionName
31+
* @param array $params
32+
* @see \Ajax\JsUtils::forward()
33+
*/
34+
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();
42+
}
43+
44+
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);
54+
}
55+
56+
public function fromDispatcher($dispatcher){
57+
return \explode("/", Router::getRequest(true)->url);
58+
}
59+
}

0 commit comments

Comments
 (0)