2013-04-11 130 views
0

我正在为Laravel4准备一个捆绑包,并且找不到如何将可配置路线添加到我的捆绑包的方法。动态laravel4服务提供商路线

实施例:

//this is from the service provider of the bundle 
public function register() 
{ 
    ... 
    $this->registerRoutes(); 
    ... 
} 

protected function registerRoutes() 
{ 
    //The way of doing into the documentation or other bundles is 
    //the problem is that I cannot put the routes to be from the config file 
    //and they cannot be overwritten from the app configuration. 
    include __DIR__ . '/routes.php'; 
} 
//This method gives an error 
protected function registerTestRoutes() 
{ 
    $this->app['imager'] = $this->app->share(function($app) 
     { 
      //$route = 'admin/images/{$image_id} 
      $route = $app['config']['imager::config']['delete_url']; 
      return \Route::delete($route, array('uses' => 'CompanyName\Imager\Controllers\[email protected]'));; 
     }); 
} 
+0

请添加一个别名到应用程序/ routes.php文件可以为您详细你得到的错误,只是说它给出了错误,并不能帮助任何人与你一起调试。 – 2013-04-11 11:43:22

回答

0

那么我发现这个问题的一个解决方案。

您不必为该应用程序创建一个配置路径。给它一个名字就足够了,那么当你的bundle在多个项目中使用,并且其中一些需要更改url时,那里的开发人员可以简单地放置一个别名。

// code from the SerivicePriveder 
public function register() 
{ 
... 
$this->registerRoutes(); 
... 
} 

protected function registerRoutes() 
{ 
include __DIR__ . '/routes.php'; 
} 

//code from the routes.php 
<?php 
Route::delete('admin/imager/{id}', array('as'=>'imager_delete', 'uses' => 'SixMinutes\Imager\Controllers\[email protected]')); 

所以,如果需要改变“管理/摄像/(编号)”你可以使用名称“imager_delete”