phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
JsUtils.php
Go to the documentation of this file.
1<?php
2
3namespace Ajax\php\symfony;
4
5
6use Symfony\Component\HttpFoundation\Request;
7use Symfony\Component\HttpKernel\HttpKernelInterface;
9class JsUtils extends \Ajax\JsUtils{
10
11 public function getUrl($url){
12 $router=$this->getInjected();
13 if(isset($router)){
14 try {
15 $url=$router->generate($url);
16 }catch (\Exception $e){
17 return $url;
18 }
19 }
20 return $url;
21 }
22 public function addViewElement($identifier,$content,&$view){
23 if(\is_array($view)){
24 if(\array_key_exists("q", $view)===false){
25 $view["q"]=array();
26 }
27 $view["q"][$identifier]=$content;
28 }elseif($view instanceof \Twig_Environment){
29 $vars=$view->getGlobals();
30 if(\array_key_exists("q", $vars)===false){
31 $vars["q"]=array();
32 }
33 $vars["q"][$identifier]=$content;
34 $view->addGlobal("q",$vars["q"]);
35 }
36 }
37
38 public function createScriptVariable(&$view,$view_var, $output){
39 $this->addVariable($view_var, $output, $view);
40 }
41
42 protected function addVariable($key,$value,&$view){
43 if(\is_array($view)){
44 $view[$key]=$value;
45 }elseif($view instanceof \Twig_Environment){
46 $view->addGlobal($key,$value);
47 }
48 }
49
57 public function forward($initialControllerInstance,$controllerName,$actionName,$params=array()){
58 $path=$params;
59 $request = $initialControllerInstance->get('request_stack')->getCurrentRequest();
60 $path['_forwarded'] = $request->attributes;
61 $path['_controller'] = $controllerName.":".$actionName;
62 $subRequest = $request->duplicate([], null, $path);
63 $response= $initialControllerInstance->get('http_kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
64 return $response->getContent();
65 }
66
67 public function renderContent($initialControllerInstance,$viewName, $params=NULL) {
68 if ($initialControllerInstance->has('templating')) {
69 return $initialControllerInstance->get('templating')->render($viewName, $params);
70 }
71
72 if (!$initialControllerInstance->has('twig')) {
73 throw new \LogicException('You can not use the "renderView" method if the Templating Component or the Twig Bundle are not available.');
74 }
75
76 return $initialControllerInstance->get('twig')->render($viewName, $params);
77 }
78
79 public function fromDispatcher($dispatcher){
80 $request = $dispatcher->get('request_stack')->getCurrentRequest();
81 $uri=$request->getPathInfo();
82 if(JString::startswith($uri, "/")){
83 $uri=\substr($uri, 1);
84 }
85 return \explode("/", $uri);
86 }
87}
JQuery PHP library.
Definition JsUtils.php:23
fromDispatcher($dispatcher)
Collects url parts from the request dispatcher : controllerName, actionName, parameters Used internal...
Definition JsUtils.php:79
getUrl($url)
Generates an URL Used internally by phpMv.
Definition JsUtils.php:11
renderContent($initialControllerInstance, $viewName, $params=NULL)
render the content of an existing view : $viewName and set the response to the modal content Used int...
Definition JsUtils.php:67
createScriptVariable(&$view, $view_var, $output)
Creates the script variable script_foot Used internally by phpMv.
Definition JsUtils.php:38
addVariable($key, $value, &$view)
Definition JsUtils.php:42
forward($initialControllerInstance, $controllerName, $actionName, $params=array())
Definition JsUtils.php:57
addViewElement($identifier, $content, &$view)
Adds the array of controls q in the $view element Used internally by phpMv.
Definition JsUtils.php:22