link generator

This commit is contained in:
Alexander Yakovlev 2022-08-17 15:50:32 +07:00
parent beae541e44
commit 0f4d2eba50
Signed by: oreolek
GPG key ID: 8D24103F5EE2A6C0
2 changed files with 43 additions and 27 deletions

View file

@ -25,6 +25,23 @@ class ViewComposer extends GenericView
*/
protected $show_create = FALSE;
protected function current_controller() {
$c = get_class(Route::current()->getController());
$c = str_replace('\\', '/', $c);
$c = basename($c);
$c = str_replace('Controller', '', $c);
$c = strtolower($c);
return $c;
}
protected function route($action, $id = 0): string {
$ret = '/'.$this->current_controller().'/'.$action;
if ($id) {
$ret.='/'.((int) $id);
}
return $ret;
}
/**
* An internal function to prepare item data.
**/
@ -45,11 +62,10 @@ class ViewComposer extends GenericView
}
if ($this->is_admin)
{
$output['edit_link'] = route('default', [
'controller' => Route::current()->getController(),
'action' => 'edit',
'id' => $item->id
]);
$output['edit_link'] = $this->route(
'edit',
(int) $item->id
);
}
// TODO Text
// $output['speed'] = '<span class="fa fa-clock-o"></span> ≈'.Text::time_to_read($item->content).' '.__('min');
@ -57,11 +73,10 @@ class ViewComposer extends GenericView
'id' => $item->id
));
$output['heading'] = $item->name;
$output['comments_link'] = route('default', array(
'controller' => Route::current()->getController(),
'action' => 'view',
'id' => $item->id
)).'#comments';
$output['comments_link'] = $this->route(
'view',
$item->id
).'#comments';
if (isset($item->password) && $item->password !== '') {
$output['content'] = _('Введите пароль для просмотра.');
} else {

View file

@ -17,20 +17,21 @@ use App\Http\Controllers\CommentController;
*/
require __DIR__.'/auth.php';
Route::get('/', [PostController::class, 'read']);
Route::get('/Post/read', [PostController::class, 'read'])->name('default');
Route::any('/Post/read/page/{page}', [PostController::class, 'read']);
Route::get('/Post/view/{id}', [PostController::class, 'view'])->name('view');
Route::get('/post/edit/{id}', [PostController::class, 'edit'])->name('post.edit');
Route::get('/page/index', [PageController::class, 'index'])->name('page.index');
Route::get('/page/view/{id}', [PageController::class, 'view'])->name('page.view');
Route::get('/page/edit/{id}', [PageController::class, 'edit'])->name('page.edit');
Route::get('/Tag/{id}', [PostController::class, 'view'])->name('tag');
Route::any('/Comment/post/{id}', [CommentController::class, 'load'])->name('comments.load');
Route::post('/Comment/post', [CommentController::class, 'post'])->name('comments.post');
Route::get('/{id}', [PostController::class, 'view']);
Route::get('/dashboard', function () {
return view('dashboard');
})->middleware(['auth'])->name('dashboard');
Route::controller(PostController::class)->group(function() {
Route::get('/', 'read');
Route::get('/Post/read', 'read')->name('post.read');
Route::any('/Post/read/page/{page}', 'read');
Route::get('/Post/view/{id}', 'view')->name('view');
Route::get('/post/edit/{id}', 'edit')->name('post.edit');
Route::get('/{id}', 'view');
});
Route::controller(PageController::class)->group(function() {
Route::get('/page/index', 'index')->name('page.index');
Route::get('/page/view/{id}', 'view')->name('page.view');
Route::get('/page/edit/{id}', 'edit')->name('page.edit');
});
// Route::get('/Tag/{id}', [PostController::class, 'view'])->name('tag');
Route::controller(CommentController::class)->group(function() {
Route::any('/Comment/post/{id}', 'load')->name('comments.load');
Route::post('/Comment/post', 'post')->name('comments.post');
});