-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAjaxableBehavior.php
47 lines (42 loc) · 956 Bytes
/
AjaxableBehavior.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* Created by PhpStorm.
* User: John
* Date: 3/17/2016
* Time: 4:08 PM
*/
namespace comradepashka\ajaxable;
use yii;
use yii\base\Behavior;
use yii\web\View;
/**
* Class AjaxableBehavior
* @package comradepashka\ajaxable
*
*/
class AjaxableBehavior extends Behavior
{
public function events()
{
return [
View::EVENT_END_BODY, [$this, 'registerToolsAsset']
];
}
public function render($view, $params = [])
{
return Yii::$app->request->isAjax ?
$this->owner->renderAjax($view, $params) :
$this->owner->render($view, $params);
}
public function init(){
yii::trace("init behavior");
}
public function registerToolsAsset($event)
{
$view = $event->sender;
yii::trace("handle END_BODY from: {$view->viewFile}");
if (yii::$app->controller == $this) {
ToolsAsset::register($view);
}
}
}