質問

これを以前に見たことはありますが、どこにも情報が見つかりません。 Zend Frameworkで.html拡張子を使用してルーティングできるようにする必要があります。

I.E。 /controller/action.htmlは適切なコントローラー/アクションにルーティングする必要があります。

.htaccessファイルで.html拡張子を捨てるというアイデアがありますが、ルート設定を変更する方がより良い解決策になると思います。

あらゆるアドバイスを歓迎します。

役に立ちましたか?

解決

Googleでクイック検索を行ったところ、次のチュートリアルが得られました。

カスタムルーティングのためのZend Frameworkルートとルーターの拡張
Zend Frameworkでのルーティングと複雑なURL

他のヒント

これは、いくつかのアプリケーションで使用したプラグインです。

/**
 * Removes .html extension from URI, if present.
 */
class Application_Plugin_RemoveHtmlExtension extends Zend_Controller_Plugin_Abstract
{
    public function routeStartup(Zend_Controller_Request_Abstract $request)
    {
        // remove ".html" from the end of the URI
        $url = preg_replace('#\.html$#i', '', $request->getRequestUri());

        $request->setRequestUri($url);
    }
}

古いアプリケーションでも同じことをしようとしていました。 これが私のために働いたものです。

$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$router->addRoute('routeHTML', new Zend_Controller_Router_Route_Regex( '([a-z-]+)/([a-z-]+)/([a-z-]+)\.html', array(),
        array(1 => 'module', 2 => 'controller', '3' => 'action') ,
        '%s/%s/%s.html')
);

デフォルトのルート(モジュールなし)は次のとおりです。

:controller/:action

次の方法で削除できます:

$router->removeDefaultRoutes();

次にバージョンを追加します:

:controller/:action.html
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top