wardrobecms / core-archived

Wardrobe Core Files

Home Page:http://wardrobecms.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Blog 'public' routes should be declared in a theme, not in core

dresfdez opened this issue · comments

Main reason, some URI segments are in english.

Moving the routes to the public folder would put a higher barrier to entry to theme developers.

I am thinking about possible localization of the post that is in the URI, but here's a few thoughts

  1. Looking at most CMS systems they do not seem to localize uris.
  2. I'm not sure if there would be a performance hit from adding another call to lang.

Looks like the include is in the routes file:
https://github.com/wardrobecms/core/blob/master/src/routes.php#L46

So all that is required is creating your theme route file and included something like this:

Route::get('/about', function()
{
        Wardrobe::setupViews();
        return View::make(Config::get('core::wardrobe.theme').'.about');
});

If we moved the Wardrobe::setupViews(); out of BaseController and into the primary routes file then it wouldn't be required here.

I think there was also a concern about the post?

Seems to work fine in my test:

$wardrobeControllers = 'Wardrobe\Core\Controllers\\';

Route::get('enviar/{slug}', array('uses' => $wardrobeControllers.'PostController@show', 'as' => 'wardrobe.posts.show'));
Route::get('post/{slug}', function()
{
    return App::abort(404, 'Page not found');
});

Then we could change the view urls to use the named route:

@foreach ($posts as $post)
    <h1><a href="{{ URL::route('wardrobe.posts.show', $post->slug) }}">{{ $post->title }}</a></h1>
@endforeach 

I think this would be a good change. Yes a little more verbose but most of the time it's probably going to be a copy and paste situation when creating new themes.

Maybe saying 'should' wasn't the best. The thing is, using lang to localize segments gets messy so moving the public routes declaration to a theme was the best solution to suggest.

'most cms' don't have reverse routing.

This is now implemented in 1.1 branch and included a new route helper in the facade:

{{ Wardrobe::route('show', $post->slug) }}

First param is the ending of the wardrobe.posts. group. I am adjusting the themes to use this and also the default theme routes has an example of over riding a default route.