Controller::flashErrors()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * Controller
5
 * @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.com.ua)
6
 * @author Aleksandr Torosh <[email protected]>
7
 */
8
9
namespace Application\Mvc;
10
11
/**
12
 * @property \Phalcon\Cache\Backend\Memcache $cache
13
 * @property \Phalcon\Mvc\View\Simple $viewSimple
14
 * @property \Application\Mvc\Helper $helper
15
 * @property \Phalcon\Http\Cookie $cookies
16
 */
17
18
class Controller extends \Phalcon\Mvc\Controller
19
{
20
21 View Code Duplication
    public function redirect($url, $code = 302)
22
    {
23
        switch ($code) {
24
            case 301:
25
                header('HTTP/1.1 301 Moved Permanently');
26
                break;
27
            case 302:
28
                header('HTTP/1.1 302 Moved Temporarily');
29
                break;
30
        }
31
        header('Location: ' . $url);
32
        $this->response->send();
33
    }
34
35
    public function returnJSON($response)
36
    {
37
        $this->view->disable();
38
39
        $this->response->setContentType('application/json', 'UTF-8');
40
        $this->response->setContent(json_encode($response));
41
        $this->response->send();
42
    }
43
44
    public function flashErrors($model)
45
    {
46
        foreach ($model->getMessages() as $message) {
47
            $this->flash->error($message);
48
        }
49
    }
50
51
    public function setAdminEnvironment()
52
    {
53
        $this->view->setMainView(MAIN_VIEW_PATH . 'admin');
54
        $this->view->setLayout(null);
55
    }
56
57
}