Completed
Push — master ( 6ada0e...35727f )
by Jean-Christophe
04:07
created

JsUtils::addViewElement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
nc 2
cc 2
eloc 5
nop 3
1
<?php
2
3
namespace Ajax\php\yii;
4
5
use yii\helpers\Url;
6
7
class JsUtils extends \Ajax\JsUtils{
8
	public function getUrl($url){
9
		if($url==="")
10
			$url="/";
11
		return Url::toRoute($url);
12
	}
13
14
	public function addViewElement($identifier,$content,$view){
15
		$params=$view->params;
16
		if (\array_key_exists("q", $params)==false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
17
			$view->params["q"]=array();
18
		}
19
		$view->params["q"][$identifier]=$content;
20
	}
21
22
	public function createScriptVariable($view,$view_var, $output){
23
		$view->params[$view_var]=$output;
24
	}
25
26
	public function forward($initialControllerInstance,$controllerName,$actionName,$params=NULL){
27
		\ob_start();
28
		$ctrInfo=\yii::$app->createController($controllerName."/".$actionName);
29
		$ctrInfo[0]->{$ctrInfo[1]}($params);
30
		$result=\ob_get_contents();
31
		\ob_end_clean();
32
		return $result;
33
	}
34
35
	public function renderContent($initialControllerInstance,$viewName, $params=NULL) {
36
		return \yii::$app->view->render($viewName,$params);
37
	}
38
39
	public function fromDispatcher($dispatcher){
40
		$uri=new \Ajax\php\yii\URI();
41
		return $uri->segment_array();
42
	}
43
}