6

カスタム バンドルで定義された単純なルートは次のとおりです。

my_admin_route:
    pattern:  /admin/{name}
    defaults: { _controller: NamespaceCustomBundle:CustomControl:login }

上記のルーティング コードはCustomControlControllerのメソッドを呼び出します。loginAction()私の質問は、各関数のようにルーティングで関数名を自動化するにはどうすればよいかということです。ルートを再度定義する必要はありません{name}。以下のようなルート

my_admin_route:
    pattern:  /admin/{name}
    defaults: { _controller: NamespaceCustomBundle:CustomControl:{name} }
4

3 に答える 3

2

Indeed this can be achieved with custom route loader as @Onema said.

I can think of two other options, none of which do exactly what you wanted but may be of interest:

1. Creating a controller action which would just forward request to other actions
2. Using @Route annotation

1.

In AdminController create action:

public function adminAction($actionName)
{
    return $this->forward('MyBundle:TargetController:' . $actionName);
}

2.

Annotation routing since it allows you to define routes without naming them. Name will be implicitly created by convention: Annotation routing.

Doesn't do exactly what you wanted but is pretty elegant too if you don't want to make custom route loader:

/**
 * @Route("/admin/dosmt")
 */
public function dosmtAction()
{
    return new Response('smtAction');
}

Additionally you can mount all controller actions on a prefix just like with YAML routing:

/**
 * @Route("/admin")
 */
class MyController extends Controller
{
    /**
     * @Route("/dosmt")
     */
    public function dosmtAction()
    {
        return new Response('smtAction');
    }
}
于 2013-09-23T07:07:11.893 に答える
2

おそらく、カスタム ルート ローダーを作成する必要があります。 を参照してください。

私の知る限り、現在、controller/method/param1/param2他のフレームワーク (CodeIgniter、FuelPHP...) のように、コントローラー -> メソッド -> パラメーターを特定のルートに直接マップするすぐに使えるソリューションはありません。

于 2013-09-22T16:28:53.060 に答える