Как передать все параметры в шаблон
19.08.2019, 21:55. Показов 1304. Ответов 0
Не пойму как передать все параметры главного шаблона в шаблон 404 ошибки с класса Handler самый последний метод
Начинает ругаться, что не определены переменные
А мне надо в этот метод public function render($request, Exception $e) передать переменные, чтобы шапка сайта и все остальное показывалось как на остальных страницах
Подскажите пожалуйста
Handler
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
| <?php
namespace App\Exceptions;
use \Exception;
use Illuminate\Validation\ValidationException;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that should not be reported.
*
* @var array
*/
protected $dontReport = [
AuthorizationException::class,
HttpException::class,
ModelNotFoundException::class,
ValidationException::class,
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* @param \Exception $e
* @return void
*/
public function report(Exception $e)
{
parent::report($e);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @return \Illuminate\Http\Response
*/
public function render($request, Exception $e)
{
if ($e instanceof HttpException) {
$status = $e->getStatusCode();
if (view()->exists("errors.$status")) {
return response(view("errors.$status"), $status);
}
}
if (env('APP_DEBUG')) {
return parent::render($request, $e);
} else {
return response(view("errors.404"), 404);
}
}
} |
|
Это контроллер
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
| <?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller as Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
use App\Services\AdmService;
class FrontController extends Controller
{
public function __construct()
{
date_default_timezone_set('Europe/Moscow');
$this->dataView['title'] = '';
$this->dataView['nav'] = [
'проекты' => 'projects',
'услуги' => 'services',
'публикации' => 'publications',
'блог' => 'blog',
'события' => 'events',
'о нас' => 'about',
'контакты' => 'contacts',
];
$this->dataView['projectStatus'] = self::STATUS;
$this->dataView['site'] = [
'insta' => 'https://www.instagram.com/_tbdesign_/',
'fb' => 'https://www.facebook.com/tbdesign.pro/',
'phone' => '79250292984',
'phoneFormat' => '+7 (925) 029-29-84',
'address' => 'Москва, Борисоглебский пер. 8с1',
'timeWork' => 'пн-пт 10:00–20:00',
'email' => 'info@tbdesign.pro',
];
$this->dataView['urlFeedback'] = route('front_contacts').'#fb';
}
public function projects() {
return $this->view('front.projects', [
'title' => 'Проекты',
'headerBack' => true,
]);
}
public function postGetProjects(Request $request) {
$type = $request->input('type');
$projects = AdmService::getProjects(['type' => $type]);
$grid = self::grid($projects, true);
$prGrid = $grid[0];
$f = $grid[1];
return $this->rqSuccess($this->render('front.block.listCardsGrid', [
'prGrid' => $prGrid,
'full' => $f,
]));
}
public function postGetPubs(Request $request) {
$type = $request->input('type');
$pubs = AdmService::getPublications(['type' => $type]);
$grid = self::grid($pubs)[0];
return $this->rqSuccess($this->render('front.block.listPubsGrid', [
'publsGrid' => $grid,
]));
}
public function posts() {
return $this->view('front.blog', [
'title' => 'Блог',
'headerBack' => true,
]);
}
public function postGetPosts(Request $request) {
$posts = AdmService::getPosts(['active' => 1]);
$grid = self::grid($posts, true);
$prGrid = $grid[0];
$f = $grid[1];
return $this->rqSuccess($this->render('front.block.listPostsGrid', [
'prGrid' => $posts,
'full' => $f,
]));
}
public function project($name) {
$project = AdmService::getProjects(['url' => $name]);
if (!$project) {
return redirect()->route('front_projects');
}
$otherProjects = AdmService::getProjects(['other' => $project->id]);
srand($project->id*256);
shuffle($otherProjects);
srand();
$otherProjects = array_slice($otherProjects, 0, 3);
$reviews = AdmService::getReviews($project->id);
return $this->view('front.project', [
'title' => $project->name,
'project' => $project,
'otherProjects' => $otherProjects,
'mainWoP' => true,
'reviews' => $reviews,
]);
}
public function post($name) {
$post = AdmService::getPosts(['url' => $name]);
if (!$post) {
return redirect()->route('front_blog');
}
srand($post->id*256);
srand();
return $this->view('front.post', [
'name' => $post->name,
'date' => $post->date,
'description' => $post->description,
'mainWoP' => true,
'text' => $post->text
]);
}
public function services() {
return $this->view('front.services', [
'title' => 'Услуги',
]);
}
public function about() {
return $this->view('front.about', [
'title' => 'О нас',
'bottomNav' => [
'события' => [false, route('front_events')],
'отзывы' => [false, route('front_reviews')],
'награды' => [false, route('front_trophies')],
'публикации' => [false, route('front_publications')],
'блог' => [false, route('front_blog')],
'инстаграм' => [true, $this->dataView['site']['insta']],
'фейсбук' => [true, $this->dataView['site']['fb']],
],
'headerInverse' => true,
]);
}
public function vacancies() {
$vacancies = AdmService::getActiveVacancies();
return $this->view('front.vacancies', [
'title' => 'Вакансии',
'headerInverse' => true,
'vacancies' => $vacancies,
]);
}
public function events() {
$events = AdmService::getEvents();
return $this->view('front.events', [
'title' => 'События',
'headerInverse' => true,
'events' => $events,
]);
}
public function trophies() {
$trophies = AdmService::getTrophies();
$trophiesGrid = self::grid($trophies)[0];
return $this->view('front.trophies', [
'title' => 'Награды',
'headerInverse' => true,
'trophiesGrid' => $trophiesGrid,
]);
}
public function publications() {
$publs = AdmService::getPublications();
$publsGrid = self::grid($publs)[0];
if (isset($_GET['dev'])) {
echo '<pre>';
print_r($publsGrid);
echo '</pre>';
}
return $this->view('front.publications', [
'title' => 'Публикации',
'headerInverse' => true,
'publsGrid' => $publsGrid,
]);
}
public function blog() {
$blog = AdmService::getPosts();
return $this->view('front.blog', [
'title' => 'Блог',
'headerInverse' => true,
'blog' => $blog,
]);
}
public function reviews() {
$reviews = AdmService::getReviewsWithProject();
return $this->view('front.reviews', [
'title' => 'Отзывы',
'headerInverse' => true,
'reviews' => $reviews,
]);
}
public function contacts() {
return $this->view('front.contacts', [
'title' => 'Контакты',
'headerInverse' => true,
]);
}
public function ty() {
return $this->view('front.ty', [
'title' => 'Спасибо за заявку',
'headerInverse' => true,
]);
}
public function postCheckFile() {
if (!empty($_FILES)) {
$file = $_FILES['file'];
$extArr = explode('.', $file['name']);
$ext = $extArr[count($extArr)-1];
$name = md5(time().'-'.basename($file['name'])).'.'.$ext;
$moveDir = base_path().'/public/storage/upload/'.$name;
if (move_uploaded_file($file['tmp_name'], $moveDir)) {
return json_encode(['name' => $file['name'], 'upload' => $name]);
}
else {
return 'error';
}
}
else {
return 'error';
}
}
public function postForm(Request $request) {
$data = $request->all();
$errors = [];
if (!isset($data['agree'])) {
$errors[] = 'Вы не дали согласие на обработу данных';
}
if (!preg_match('/^.+@.+\..+$/', $data['email'])) {
$errors[] = 'Email заполнен не верно';
}
if (!preg_match('/^.*\d{3}.*\d{3}.*\d{2}.*\d{2}$/', $data['phone'])) {
$errors[] = 'Телефон заполнен не верно';
}
if (count($errors)) {
return $this->rqError(implode(', ', $errors));
}
else if (AdmService::form($data)) {
return $this->rqSuccess(route('front_ty'));
}
else {
return $this->rqError();
}
}
public static function grid($arr, $endFB = false) {
$s = ['l' => 0, 'r' => 0];
$prGrid = ['l' => [], 'r' => []];
foreach ($arr as $p) {
$side = $s['l'] > $s['r'] ? 'r' : 'l';
$prGrid[$side][] = $p;
$s[$side] = $s[$side] + ($p->orient == 'v' ? 2 : 1);
}
if ($s['l'] == $s['r']) {
$f = true;
}
else {
if ($endFB) {
if ($s['l'] > $s['r']) {
$prGrid['r'][] = 'fb';
}
else {
$prGrid['l'][] = 'fb';
}
}
$f = false;
}
return [$prGrid, $f];
}
} |
|
Тут роуты
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
| <?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
// $router->get('/', function () use ($router) {
// return $router->app->version();
// });
foreach ([
'/' => 'projects',
'projects/{name:[A-Za-z0-9-]+}' => 'project',
'services' => 'services',
'vacancies' => 'vacancies',
'events' => 'events',
'trophies' => 'trophies',
'publications' => 'publications',
'blog' => 'blog',
'blog/{name:[A-Za-z0-9-]+}' => 'post',
'reviews' => 'reviews',
'about' => 'about',
'contacts' => 'contacts',
'thank-you' => 'ty',
'dev' => 'dev',
] as $url => $action) {
$router->get($url, ['as' => 'front_'.$action, 'uses' => 'FrontController@'.$action]);
}
foreach ([
'ajax/checkFile' => 'checkFile',
'form' => 'form',
'getProjects' => 'getProjects',
'getPosts' => 'getPosts',
'getPubs' => 'getPubs',
] as $url => $action) {
$action = 'post'.ucfirst($action);
$router->post($url, ['as' => 'front_'.$action, 'uses' => 'FrontController@'.$action]);
}
$router->group(['prefix' => 'adm', 'middleware' => 'admMW'], function() use ($router) {
foreach ([
'/' => 'projects',
'login' => 'login',
'projects/add' => 'addProject',
'projects/{id:[0-9]+}' => 'editProject',
'authors' => 'authors',
'authors/add' => 'addAuthor',
'authors/{id:[0-9]+}' => 'editAuthor',
'posts' => 'posts',
'post/{id:[0-9]+}' => 'editPost',
'post/add' => 'addPost',
'vacancies' => 'vacancies',
'vacancy/add' => 'addVacancy',
'vacancy/{id:[0-9]+}' => 'editVacancy',
'events' => 'events',
'event/add' => 'addEvent',
'event/{id:[0-9]+}' => 'editEvent',
'publications' => 'publications',
'publication/add' => 'addPublication',
'publication/{id:[0-9]+}' => 'editPublication',
'trophies' => 'trophies',
'trophy/add' => 'addTrophy',
'trophy/{id:[0-9]+}' => 'editTrophy',
'projects/{project:[0-9]+}/reviews' => 'reviews',
'projects/{project:[0-9]+}/reviews/add' => 'addReview',
'review/{id:[0-9]+}' => 'editReview',
] as $url => $action) {
$router->get($url, ['as' => 'adm_'.$action, 'uses' => 'AdmController@'.$action]);
}
foreach ([
'login' => 'login',
'ajax/checkFile' => 'checkFile',
'project' => 'project',
'author' => 'author',
'blog' => 'blog',
'posts' => 'posts',
'post' => 'post',
'vacancy' => 'vacancy',
'event' => 'event',
'trophy' => 'trophy',
'publication' => 'publication',
'review' => 'review',
'getProjectBlock' => 'getProjectBlock',
'projectActive' => 'projectActive',
'vacancyActive' => 'vacancyActive',
'eventActive' => 'eventActive',
'postActive' => 'postActive',
'publicationActive' => 'publicationActive',
'trophyActive' => 'trophyActive',
'reviewActive' => 'reviewActive',
'sortItems' => 'sortItems',
] as $url => $action) {
$action = 'post'.ucfirst($action);
$router->post($url, ['as' => 'adm_'.$action, 'uses' => 'AdmController@'.$action]);
}
}); |
|
0
|