下面的代碼說明了一切......Laravel 4:從make傳遞數據到服務提供商
// routes.php
App::make('SimpleGeo',array('test')); <- passing array('test')
// SimpleGeoServiceProvider.php
public function register()
{
$this->app['SimpleGeo'] = $this->app->share(function($app)
{
return new SimpleGeo($what_goes_here);
});
}
// SimpleGeo.php
class SimpleGeo
{
protected $_test;
public function __construct($test) <- need array('test')
{
$this->_test = $test;
}
public function getTest()
{
return $this->_test;
}
}
你好@schmaltz你有問題嗎?我有同樣的問題,並尋找一個解決方案,因爲我的應用程序使用類似的架構,像你的.. – Omranic 2014-02-13 05:40:23