2017 © Pedro Peláez
 

library router

image

corvo/router

  • Friday, May 16, 2014
  • by LisandroSeijo
  • Repository
  • 2 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

CorvoRoutes

Simple way to organize Laravel proyects., (*1)

If you wanna contribute, please, fork or open an issue., (*2)

If you have a question, sand me a tweet, or join on Laraveles (Laravel in spanish)., (*3)

How to use

Instalation

Add "corvo/router" in your composer.json requires and run composer update., (*4)

require {
    ...,
    "corvo/router": "dev-master"
}

Note: if you use namespaces in your sections add app/web with psr-0 or psr-4 on composer.json, (*5)

autoload {
    "classmap": [
      ...
    ],
    "psr-0": {
      "": "app/web"
    }
}

Add Corvo\Routes\Providers\CorvoRoutesServiceProvider in your app/config/app.php file, (*6)

'providers' => array(
  'Illuminate\Foundation\Providers\ArtisanServiceProvider',
  ...
  'Corvo\Routes\Providers\CorvoRoutesServiceProvider'
)

Now, the easy way to create sections is using artsian, run the following command in your root application folder:, (*7)

php artsian corvo:section [section_name]

That create a section called [section_name]. For example, lets to create a section for a blog, (*8)

php artsian corvo:section Blog

And an admin section, (*9)

php artsian corvo:section Admin

See in your proyect/app folder, and open the new folder named web, this contain all sections, and now we have the Blog and Admin sections., (*10)

You must have something like that:, (*11)

|--app
|--|--web
|--|--|--Blog
|--|--|--|--Config
|--|--|--|--Controllers
|--|--|--|--Library
|--|--|--|--Models
|--|--|--|--routes.php
|--|--|--|--Views
|--|--|--Admin
|--|--|--|--Config
|--|--|--|--Controllers
|--|--|--|--Library
|--|--|--|--Models
|--|--|--|--routes.php
|--|--|--|--Views

Namespaces

Now what we have the sections, go to create the views:, (*12)

/* app/web/Blog/Views/index.blade.php */



My Awsome Blog!

@foreach($posts as $post)

{{ $post->title }}

{{ $post->content }}, (*13)

@endforeach

For access to this view, we can use the namespaces called in the same way as section., (*14)

Add in the Blog/routes.php file:, (*15)

/* app/web/Blog/routes.php */

Route::group(array('prefix' => 'blog'), function ()
{
  Route::get('/', function()
  {
    $posts = Blog\Models\Post::all();
    return View::make('Blog::index', ['posts' => $posts]);
  });
});

The Blog namespace is already added, and we can use that for do refence to all Blogs views., (*16)

The same way in our Admin views, and all sections:, (*17)

/* app/web/Admin/routes.php */

Route::group(array('prefix' => 'admin'), function ()
{
  Route::get('/users', function()
  {
    $users = Admin\Models\Users::all();
    return View::make('Admin::users', ['users' => $users]);
  });
});

To access to config files is the same way:, (*18)

/* app/web/Blog/Config/general.php */

return array(
  'posts_per_page' => 10
);

```php /* app/web/Blog/Controllers/HomeController.php */, (*19)

public function getIndex() { $postsPerPage = Config::('Blog::general.posts_per_page'); $posts = Blog\Models\Post::take($postsPerPage)->get(); return View::make('Blog::index', ['posts' => $posts]); }, (*20)

#Runing
To run this, we need load CorvoRoutes class. To do that, in the `proyect/app/routes.php` file add the following line:
```php
/* app/routes.php */

CorvoRoutes::load();

And that's all., (*21)

Advanced usage:

Configuration

You can change the some features of CorvoRoutes like the path of sections, routes filename or the name of view folder., (*22)

In your proyect/app/config folder create a new config file called corvoroutes, (*23)

|--app
|--|--config
|--|--|--corvoroutes.php

In this file, you can change one or more features., (*24)

Options:, (*25)

Name Description
base_path Change the base path of your sections location
alternative_paths Array which contain the absolute path to other sections location
routes_filename Name of your routes file
views_folder Name of your views folder

For example, if you wanna change the views folder /Views for /Templates, only add this option:, (*26)

/* proyect/app/config/corvoroutes.php */

return array(
    'views_folder' => 'Templates'
);

And change the base_path, you don't like proyect/app/web and think is better proyect/content:, (*27)

/* proyect/app/config/corvoroutes.php */

return array(
    'base_path'    => base_path().'/content',
    'views_folder' => 'Templates'
);

Note: if you change base_path and created previous sections in proyect/app/web you must move to the new base_path or add with alternative_paths, (*28)

Alternative paths

For add a section in other location like proyect/content/Foro/ and proyect/Users/ you have two was:, (*29)

1) Using config file:, (*30)

return array(
    'alternative_paths' => array(
        base_path().'/content/Foro',
        base_path().'/Users'
    )
);

2) Using alternativePaths() method, (*31)

/* proyect/app/routes.php */

CorvoRoutes::alternativePaths(array(
    base_path().'/content/Foro',
    base_path().'/Users'
))
->load();

And each "alternative path" work like proyect/app/web sections., (*32)

The Versions

16/05 2014

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Lisandro Seijo