2

基本的に、私は何年にもわたって独自のフレームワークを開発してきました。欠けているのは、中央ルーティング システムです。車輪を再発明する代わりに、スタンドアロンのルーティング ライブラリをフレームワークに統合したいと考えています。

スタンドアロンの PHP ルーティング ライブラリはありますか?
ない場合は、開発のガイドラインを提案できますか?

F3フレームワークのようなものが欲しい:

$route->add( 'article/view/[0-9]+' );  //> Call Article->view(); (website.net/article/id/123)
$route->add( 'email', 'email.php' ); //> Run email.php (website.net/email)

編集

私は独自に開発しました。使用例は次のとおりです。

   // index.php

   require 'router.php';

   $router = new Router();

   $router
     //> It will require controllers/article.php and call one of the view,etc method
     ->add('(article)/(view|edit|delete|add)/([0-9]+)')

     //> Same thing as before, but this time we use underscore as separator
     //> It will require controllers/entry.php and call view method
     ->add('(entry)_(view)_([0-9]+)')

     //> Or you can require custom file like this
     ->add( '(myCustomPage)' , '/controllers/myCustomPath/myPage.php' )

     ->dispatch();

シンプルなコントローラーが必要な場合は、クラスを指定せずに関数を直接実行できます。例:

   // myCustomController.php
   function myCustomController($id) {
     echo 'I am the Custom Controller';
   }

   // index.php
   $router
      ->add('(myCustomController)/([0-9]+)');

   // The routing system will detect there is a function and will call it directly.
   // Otherwise will just instanciate a new myCustomController() object

もちろん、次のような検索エンジン フレンドリー URL を使用できます。

   //> This will match something like this: article/123/your-title-here
   ->add('(article)/([0-9]+)/[a-z0-9-]+')

次のように、カスタム コントローラーからカスタム メソッドを実行できます。

   ->add('(ctrlname)/(methodname)/(params)', array('CustomControllerName','CustomMethod') );

ソース: http://pastebin.com/9F02GEyN

4

1 に答える 1

3

Symfony Routingコンポーネント、または単一のPHPファイルにラップされたSinatraに着想を得たツールであるbrilliantklein.phpルーターのいずれかを使用できます。

于 2012-10-28T11:24:49.737 に答える