1 | <?php |
||||||
2 | |||||||
3 | use Pages\IPage; |
||||||
4 | |||||||
5 | /** |
||||||
6 | * Created by Gorlum 10.02.2017 6:36 |
||||||
7 | */ |
||||||
8 | class AjaxController { |
||||||
9 | |||||||
10 | /** |
||||||
11 | * |
||||||
12 | * Request format: |
||||||
13 | * http://xxx/index.php?page=ajax&mode=MODE&action=ACTION |
||||||
14 | * |
||||||
15 | * Will call method Pages\Page<MODE>.<ACTION>() |
||||||
16 | * |
||||||
17 | * @param template|null $template |
||||||
18 | * |
||||||
19 | * @return template|null |
||||||
20 | */ |
||||||
21 | public static function controller($template = null) { |
||||||
22 | global $template_result; |
||||||
23 | |||||||
24 | define('IN_AJAX', true); |
||||||
25 | |||||||
26 | if(!is_object($template)) { |
||||||
27 | $template = SnTemplate::gettemplate('_ajax', true); |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
28 | } |
||||||
29 | |||||||
30 | $template_result = array_merge($template_result, $merge = array( |
||||||
31 | 'GLOBAL_DISPLAY_HEADER' => false, |
||||||
32 | 'GLOBAL_DISPLAY_MENU' => false, |
||||||
33 | 'GLOBAL_DISPLAY_NAVBAR' => false, |
||||||
34 | |||||||
35 | 'IN_AJAX' => true, |
||||||
36 | )); |
||||||
37 | |||||||
38 | $template->assign_vars($merge); |
||||||
39 | |||||||
40 | !is_array($template_result['AJAX']) ? $template_result['AJAX'] = array() : false; |
||||||
41 | |||||||
42 | $mode = sys_get_param_str('mode'); |
||||||
43 | |||||||
44 | if ( |
||||||
45 | class_exists($className = 'Pages\\PageAjax' . ucfirst($mode)) |
||||||
46 | || |
||||||
47 | // Deprecated. Use 1st form! Only for back compatibility! |
||||||
48 | class_exists($className = 'Pages\\Page' . ucfirst($mode)) |
||||||
49 | ) { |
||||||
50 | /** |
||||||
51 | * @var IPage $page |
||||||
52 | */ |
||||||
53 | $page = new $className(); |
||||||
54 | if(method_exists($page, 'loadParams')) { |
||||||
55 | $page->loadParams(); |
||||||
56 | } |
||||||
57 | |||||||
58 | if(method_exists($page, $action = sys_get_param_str('action')) && $page->checkAction($action)) { |
||||||
59 | $result = $page->$action(); |
||||||
60 | is_array($result) ? HelperArray::merge($template_result['AJAX'], $result) : false; |
||||||
61 | } |
||||||
62 | } |
||||||
63 | |||||||
64 | return $template; |
||||||
65 | } |
||||||
66 | |||||||
67 | /** |
||||||
68 | * @param template|null $template |
||||||
69 | * |
||||||
70 | * @return template|null |
||||||
71 | */ |
||||||
72 | public static function view($template = null) { |
||||||
73 | global $template_result; |
||||||
74 | |||||||
75 | $template->assign_var('AJAX_RENDERED', json_encode($template_result['AJAX'])); |
||||||
0 ignored issues
–
show
The method
assign_var() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
76 | |||||||
77 | return $template; |
||||||
78 | } |
||||||
79 | |||||||
80 | } |
||||||
81 |