在Laravel 4中获取子域路由错误

时间:2013-07-03 15:15:08

标签: laravel laravel-4

感谢您花时间阅读我的帖子。

我目前正在尝试将我的Laravel 4设置设置为多租户环境。我检查了Laravel论坛,我跟随了一个由Wyred在那里发布的帖子,这是帖子http://forums.laravel.io/viewtopic.php?id=9315的链接。

在关注此帖后,我创建了子域,并且正在将子域正确地发送到路由。当我登录时,我确信我正在对租户数据库进行身份验证,因为它允许我使用仅在租户数据库中创建的用户名登录,但一旦登录(我使用Zizaco的Confide for AUTH)并重定向我到我的控制器索引我得到一个错误,说

错误:

Symfony \ Component \ Routing \ Exception \ MissingMandatoryParametersException
Some mandatory parameters are missing ("subdomain") to generate a URL for route {subdomain}.recordsynergy.com get patient/index/{v1}/{v2}/{v3}/{v4}/{v5}".

我已经看过问题是什么,但一直无法找到它。在UrlGenerator.php中,我有dd()抛出此异常的值,但它显示了子域的值。现在,当我在getLogin Auth页面之前执行dd()时,它会将子域显示为类似于此数组的数组('subdomain'=>'这里是'实际子域')。当我在索引页面的控制器中执行它时,它只显示str3(实际子域),但没有数组。所以我不确定问题是什么。希望通过代码粘贴,有人可以提供帮助。谢谢!

 Error: 
Symfony \ Component \ Routing \ Exception \ MissingMandatoryParametersException
Some mandatory parameters are missing ("subdomain") to generate a URL for route "{subdomain}.recordsynergy.com get patient/index/{v1}/{v2}/{v3}/{v4}/{v5}".
Symfony\Component\Routing\Exception\MissingMandatoryParametersException
…/­vendor/­symfony/­routing/­Symfony/­Component/­Routing/­Generator/­UrlGenerator.php155
open: /var/www/recordsynergy/vendor/symfony/routing/Symfony/Component/Routing/Generator/UrlGenerator.php
    ~~~~~ Routes.php ~~~~~~
    <?php
    /*
    |--------------------------------------------------------------------------
    | Application Routes
    |--------------------------------------------------------------------------
    |
    | Here is where you can register all of the routes for an application.
    | It's a breeze. Simply tell Laravel the URIs it should respond to
    | and give it the Closure to execute when that URI is requested.
    |
    Route::get('/', function()
    {
    return View::make('hello');
    });
    */
    $subdomain = '';
    $domain_parts = explode('.', Request::server('HTTP_HOST'));
    if (count($domain_parts) == 3) {
    $subdomain = $domain_parts[0];
    if ($subdomain == 'www') {
        $subdomain = '';
    }
    }
    if (empty($subdomain)) {
    //create routes meant for webapp.com or www. webapp.com
    Route::get('/','UserController@getLogin');
    } else {
    //create routes meant for tenant.webapp.com
    Route::group(array('domain' => '{subdomain}.'.Config::get('app.domain'), 'before' => 'db.setup'), function() {
        //login, logout
        Route::get('/','UserController@getLogin');
    ;
        });
        //routes that require login
        //REMEMBER that the db.setup filter must be run first in order to change the database     to the tenant's so that your sessions will be read from the correct database
    Route::group(array('domain' => '{subdomain}.'.Config::get('app.domain'), 'before' =>     'db.setup|auth'), function() {
        Route::controller('patient','PatientController');
        });
    }
    Route::group(array('before' => 'force_ssl'), function()
    {
    Route::get('/','UserController@getLogin');
    //Defining Controllers
    Route::controller('patient','PatientController');
    Route::controller('user', 'UserController');
    Route::controller('note', 'DailyNoteController');
    Route::controller('eval', 'EvalController');
    Route::controller('billing', 'BillingController');
    Route::controller('insurance', 'InsuranceController');
    //End Defining Controllers
    Route::get('/forgot', 'UserController@getForgot');
    Route::get('/cpt', 'PatientController@getCpt');
    //Route::get('user/confirm/{code}', 'UserController@getReset');
    //Route::get('user/reset/{token}', 'UserController@getReset');
    });
    Route::when('patient*','auth');
    Route::get('/icd9', 'PatientController@getJSON');
    // Confide RESTful route
    //Route::controller( 'user', 'UserController');// Confide RESTful route
    ~~~~~~~~~~~~~ END Routes.php ~~~~~~~~~~~~~
    ~~~~~~~~~~~~~~ Filters ~~~~~~~~~~~~~~~~
    <?php
    /*
    |--------------------------------------------------------------------------
    | Application & Route Filters
        |
    | Below you will find the "before" and "after" events for the application
    | which may be used to do any work before or after a request into your
    | application. Here you may also register your custom route filters.
    |
    */
    App::before(function($request)
    {
    //
    });
    App::after(function($request, $response)
        {
    //
    });
    Route::filter('force_ssl', function()
    {
    if(!Request::secure())
    {
        return Redirect::secure(Request::getRequestUri());
    }
    });
    Route::filter('db.setup', function($route, $request) {
    $host = $request->getHost();
    $parts = explode('.', $host);
    $subdomain = $parts[0];
    $tenant = Tenant::whereSubdomain($subdomain)->first();
    $domain = Config::get('app.domain');
    //unable to find tenant in database, redirect to myapp.com
    if ($tenant == null) return Redirect::to('http://'.Config::get('app.domain'));
    //set the default database connection to the tenant database
        Config::set('database.connections.mysql_tenant.database', 'RS_'.strtoupper($subdomain));
        DB::setDefaultConnection('mysql_tenant');
    });
    /*
    |--------------------------------------------------------------------------
        | Authentication Filters
    |--------------------------------------------------------------------------
    |
    | The following filters are used to verify that the user of the current
    | session is logged into this application. The "basic" filter easily
    | integrates HTTP Basic authentication for quick, simple checking.
    |
    */
    Route::filter('auth', function()
    {
    if (Auth::guest()) return Redirect::guest('/user/login');
    });
    Route::filter('auth.basic', function()
    {
    return Auth::basic();
    });
    /*
    |--------------------------------------------------------------------------
    | Guest Filter
    |--------------------------------------------------------------------------
    |
    | The "guest" filter is the counterpart of the authentication filters as
    | it simply checks that the current user is not logged in. A redirect
    | response will be issued if they are, which you may freely change.
    |
    */
    Route::filter('guest', function()
    {
    if (Auth::check()) return Redirect::to('/');
    });
    /*
    |--------------------------------------------------------------------------
    | CSRF Protection Filter
    |--------------------------------------------------------------------------
    |
    | The CSRF filter is responsible for protecting your application against
    | cross-site request forgery attacks. If this special token in a user
    | session does not match the one given in this request, we'll bail.
    |
    */
    Route::filter('csrf', function()
    {
    if (Session::token() != Input::get('_token'))
    {
        throw new Illuminate\Session\TokenMismatchException;
    }
    });
    ~~~~~~~~~~~ END FILTERS ~~~~~~~~~~~~~
    ~~~~~~~~~~User Controller Login Function ~~~~~~~~~~~~~
    public function getLogin($subdomain)
    {   $data['subdomain'] = $subdomain;

        if( Confide::user() )
        {
            // If user is logged, redirect to internal 
            // page, change it to '/admin', '/dashboard' or something
            return Redirect::action('PatientController@getIndex', $data);
        }
        else
        {
            return View::make(Config::get('confide::login_form'), $data);
        }
    }
    ~~~~~~~~~~~~~ End User Login Func ~~~~~~~~~~~~~~
    ~~~~~~~~~~~~~ Patient Controller Get Index Function ~~~~~~~~~~~~~~
    public function getIndex($subdomain)
    {
        $data['subdomain'] = $subdomain;

        return View::make('patients.index',$data)
        ->with('patients', Patient::where('cc_id',Auth::user()->cc_id)->orderBy('last')->get());
    }
    ~~~~~~~~~ End Patient Controller Get Index ~~~~~~~~~~~~~~
    ~~~~~~~~~~~ Patient.Index View ~~~~~~~~~~~~~~~~~
    @extends('layouts.default')

    @section('content')
  <title>Dashboard</title>
 <h1>Patient Dashboard </h1>
   <table class="table table-striped">
    <thead>
        <tr>
            <th>Name</th>
        </tr>
        <tbody>
    @foreach($patients as $patient)
        <tr>
        <?php if($patient->middle){
         $name = $patient->last.", ". $patient->first." ".$patient->middle.".";
        }else{
            $name = $patient->last.", ". $patient->first;

    }?>
            <td>{{ HTML::linkAction('PatientController@getInfo',$name,
                                      array($patient->patients_id)) }}
            </td>
            <td>
            <ul class="unstyled inline" style="display:inline">
                <li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown"><b class="icon-plus"></b></a>
                    <ul class="dropdown-menu">
                        <li><a href="{{ Action('EvalController@getNewEval',
                                [$patient->patients_id]) }}"><i class="icon-plus-sign"></i> New Eval</a></li>
                        <li><a href="{{ Action('DailyNoteController@getNewNote',
                                [$patient->patients_id]) }}"><i class="icon-plus-sign"></i> New Note</a></li>
            </ul>
            <a href="{{ Action('PatientController@getEdit',
                                [$patient->patients_id]) }}" class="icon-edit"></a>
            <a href="{{ Action('PatientController@getDelete',
                                [$patient->patients_id]) }}" class="icon-remove" 
                                    onclick='return confirm("CONFIRM: Delete Patient?")'></a>

            </td>
        </tr>
    @endforeach
        </tbody>
</table>

@stop

0 个答案:

没有答案