0

Kohana 3.3 を使用して、タブ付きのインターフェイスを作成し、ルート パラメーターに基づいてアクティブなタブを検出しようとしています。

次のような 2 つの URL でのテスト:mysite.com/p/mycontroll および:mysite.com/p/Francis-Lewis/mycontroll

私のルートは次のようになります。

Route::set('profile', 'p(/<name>)(/<controller>(/<action>))', array(
        'name'          => '[\w\-]+',
        'controller'    => '[a-z]+',
        'action'        => '(view|edit|save|delete|create|cancel)',
    ))->defaults(array(
        'name'          => null,
        'directory'     => 'profile',
        'controller'    => 'main',
        'action'        => 'index',
    )); 

ルート自体は正常に機能しており、mycontrollコントローラーを選択しています。ここで問題が発生します。コントローラーでは、次のようになります。

$this->request->param('controller'); // returns NULL

ビューで

<?= Request::current()->param('controller') ?> // returns NULL

しばらく頭を悩ませた後、Kohana Request クラスに関数を追加して、$_params配列を返してそこに何が入っているかを確認しました。

返されるのは次のとおりです。

name => 'Francis Lewis'

現在のコントローラーを取得する方法はありますか?

4

2 に答える 2

1

そのための関数が request オブジェクトにあります:

$this->request->controller(); // Returns the current controller as a String
于 2013-07-11T09:39:25.663 に答える
0

最初のコントローラーが必要であることが確実な場合は、次の方法を使用できます。

Request::initial()->controller();

それ以外の場合は、次の方法を使用します。

Request::current()->controller();
于 2013-07-30T06:34:32.597 に答える