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
2namespace Ajax\php\ci;
3
4class JsUtils extends \Ajax\JsUtils{
5 protected $ci;
6 protected $_my_controller_paths= array();
7 protected $_my_controllers= array();
8
9 public function __construct($params=array(),$injected=NULL){
10 parent::__construct($params,$injected);
11 $this->_my_controller_paths = array(APPPATH);
12 }
13 public function getUrl($url){
14 return site_url($url);
15 }
16
17 public function getCi(){
18 if(isset($this->ci)===false){
19 $this->ci =& get_instance();
20 $this->ci->load->helper('url');
21 }
22 return $this->ci;
23 }
24
25 public function addViewElement($identifier,$content,&$view){
26 if(\array_key_exists("q", $view)===false){
27 $view["q"]=array();
28 }
29 $view["q"][$identifier]=$content;
30 }
31
32 public function createScriptVariable(&$view,$view_var, $output){
33 $view[$view_var]=$output;
34 }
35
36 public function forward($initialControllerInstance,$controllerName,$actionName,$params=NULL){
37 $ci=$this->getCi();
38 $controllerName=strtolower($controllerName);
39 $this->controller($controllerName);
40 \ob_start();
41 $ci->{$controllerName}->{$actionName}($params);
42 $result=ob_get_contents();
43 \ob_end_clean();
44 return $result;
45 }
46
47 public function renderContent($initialControllerInstance,$viewName, $params=NULL) {
48 return $initialControllerInstance->load->view($viewName, $params, true);
49 }
50
51 public function fromDispatcher($dispatcher){
52 return array_values($dispatcher->uri->segment_array());
53 }
54
55 public function controller($controller, $name = '', $db_conn = FALSE){
56 if (\is_array($controller)){
57 foreach ($controller as $babe){
58 $this->controller($babe);
59 }
60 return;
61 }
62 if ($controller == ''){
63 return;
64 }
65 $path = '';
66 // Is the controller in a sub-folder? If so, parse out the filename and path.
67 if (($last_slash = strrpos($controller, '/')) !== FALSE){
68 // The path is in front of the last slash
69 $path = substr($controller, 0, $last_slash + 1);
70 // And the controller name behind it
71 $controller = substr($controller, $last_slash + 1);
72 }
73
74 if ($name == ''){
75 $name = $controller;
76 }
77
78 if (in_array($name, $this->_my_controllers, TRUE)){
79 return;
80 }
81
82 $CI =$this->getCi();
83 if (isset($CI->$name)){
84 show_error('The controller name you are loading is the name of a resource that is already being used: '.$name);
85 }
86 $controller = strtolower($controller);
87 foreach ($this->_my_controller_paths as $mod_path){
88 if ( ! file_exists($mod_path.'controllers/'.$path.$controller.'.php')){
89 continue;
90 }
91 if ($db_conn !== FALSE && ! class_exists('CI_DB')){
92 if ($db_conn === TRUE){
93 $db_conn = '';
94 }
95 $CI->load->database($db_conn, FALSE, TRUE);
96 }
97 if ( ! class_exists('CI_Controller')){
98 load_class('Controller', 'core');
99 }
100 require_once($mod_path.'controllers/'.$path.$controller.'.php');
101 $controller = ucfirst($controller);
102 $CI->$name = new $controller();
103
104 $this->_my_controllers[] = $name;
105 return;
106 }
107 show_error('Unable to locate the controller you have specified: '.$controller);
108 }
109}
JQuery PHP library.
Definition JsUtils.php:23
fromDispatcher($dispatcher)
Collects url parts from the request dispatcher : controllerName, actionName, parameters Used internal...
Definition JsUtils.php:51
forward($initialControllerInstance, $controllerName, $actionName, $params=NULL)
Forwards to.
Definition JsUtils.php:36
getUrl($url)
Generates an URL Used internally by phpMv.
Definition JsUtils.php:13
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:47
controller($controller, $name='', $db_conn=FALSE)
Definition JsUtils.php:55
createScriptVariable(&$view, $view_var, $output)
Creates the script variable script_foot Used internally by phpMv.
Definition JsUtils.php:32
__construct($params=array(), $injected=NULL)
Definition JsUtils.php:9
addViewElement($identifier, $content, &$view)
Adds the array of controls q in the $view element Used internally by phpMv.
Definition JsUtils.php:25