1
|
|
|
<?php |
2
|
|
|
namespace App\Controller; |
3
|
|
|
|
4
|
|
|
use Cake\Core\Configure; |
5
|
|
|
use Cake\Event\Event; |
6
|
|
|
use Cake\Network\Exception\NotFoundException; |
7
|
|
|
|
8
|
|
|
class PagesController extends AppController |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Components. |
13
|
|
|
* |
14
|
|
|
* @var array |
15
|
|
|
*/ |
16
|
|
|
public $components = [ |
17
|
|
|
'RequestHandler' |
18
|
|
|
]; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Beforefilter. |
22
|
|
|
* |
23
|
|
|
* @param Event $event The beforeFilter event that was fired. |
24
|
|
|
* |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
|
|
public function beforeFilter(Event $event) |
28
|
|
|
{ |
29
|
|
|
parent::beforeFilter($event); |
30
|
|
|
|
31
|
|
|
$this->Auth->allow(['home', 'acceptCookie', 'lang', 'terms']); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Home page. |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
public function home() |
40
|
|
|
{ |
41
|
|
|
$this->loadModel('BlogArticles'); |
42
|
|
|
$this->loadModel('BlogArticlesComments'); |
43
|
|
|
|
44
|
|
|
$articles = $this->BlogArticles |
|
|
|
|
45
|
|
|
->find() |
46
|
|
|
->contain([ |
47
|
|
|
'BlogCategories', |
48
|
|
|
'Users' |
49
|
|
|
]) |
50
|
|
|
->order([ |
51
|
|
|
'BlogArticles.created' => 'desc' |
52
|
|
|
]) |
53
|
|
|
->limit(Configure::read('Home.articles')) |
54
|
|
|
->where([ |
55
|
|
|
'BlogArticles.is_display' => 1 |
56
|
|
|
]); |
57
|
|
|
|
58
|
|
|
$comments = $this->BlogArticlesComments |
|
|
|
|
59
|
|
|
->find() |
60
|
|
|
->contain([ |
61
|
|
|
'BlogArticles' => function ($q) { |
62
|
|
|
return $q |
63
|
|
|
->select([ |
64
|
|
|
'title' |
65
|
|
|
]); |
66
|
|
|
}, |
67
|
|
|
'Users' => function ($q) { |
68
|
|
|
return $q->find('medium'); |
69
|
|
|
} |
70
|
|
|
]) |
71
|
|
|
->order([ |
72
|
|
|
'BlogArticlesComments.created' => 'desc' |
73
|
|
|
]) |
74
|
|
|
->limit(Configure::read('Home.comments')) |
75
|
|
|
->where([ |
76
|
|
|
'BlogArticles.is_display' => 1 |
77
|
|
|
]); |
78
|
|
|
|
79
|
|
|
$this->set(compact('articles', 'comments')); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* The user accept the use of cookies. |
84
|
|
|
* |
85
|
|
|
* @throws \Cake\Network\Exception\NotFoundException When it's not an AJAX request. |
86
|
|
|
* |
87
|
|
|
* @return void |
88
|
|
|
*/ |
89
|
|
|
public function acceptCookie() |
90
|
|
|
{ |
91
|
|
|
if (!$this->request->is('ajax')) { |
92
|
|
|
throw new NotFoundException(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$this->Cookie->configKey('allowCookies', [ |
96
|
|
|
'expires' => '+1 year', |
97
|
|
|
'httpOnly' => true |
98
|
|
|
]); |
99
|
|
|
$this->Cookie->write('allowCookies', 'true'); |
100
|
|
|
|
101
|
|
|
$json = []; |
102
|
|
|
$json['message'] = __('Thanks for accepting to use the cookies !'); |
103
|
|
|
$this->set(compact('json')); |
104
|
|
|
|
105
|
|
|
$this->set('_serialize', 'json'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Redirect to the referer. |
110
|
|
|
* |
111
|
|
|
* @return void |
112
|
|
|
*/ |
113
|
|
|
public function lang() |
114
|
|
|
{ |
115
|
|
|
$this->redirect($this->referer()); |
|
|
|
|
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Display the Terms page. |
120
|
|
|
* |
121
|
|
|
* @return void |
122
|
|
|
*/ |
123
|
|
|
public function terms() |
124
|
|
|
{ |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.