0

非常に単純な MVC フレームワークをまだ見つけていません。フレームワークはどのようにして URL だけでコントローラにアクセスできるようにするのですか? と関係があると思いますが、QUERY_STRINGあると思われません?か?

http://localhost/public/controllername

次の場所にlocalhost/publicあります。

C:\wamp\www\public\

index.php を含む

4

2 に答える 2

1

一般に、これは.htaccess書き換え ( Apache mod_rewrite )を使用して行われます。

  1. .htaccess書き換えを使用して、静的ファイルではないすべてのクエリをメイン エントリ ポイントに送信します。たとえばindex.php、PHP をサーバー側言語として使用するとします。
  2. 次に、URI を内部から解析index.phpし、アプリケーションでいくつかのルートを確立します。

簡単な例:

.htaccessファイル:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

index.phpファイル:

$uri = $_SERVER['REQUEST_URI'];
$parts = explode('/', $uri);
// assuming you want /controller/action/* mapping
$controller = 'index'; // default
$action = 'index'; // default
if (isset($parts[0])) $controller = $parts[0];
if (isset($parts[1])) $action = $parts[1];
// now, you'd try to establish some logic to test wether this controller/action
// actually exists, and load it. I'll leave this up to you.

もちろん、これは簡単で大まかな例にすぎませんが、これを行う方法のアイデアを提供する必要があります。

于 2012-04-10T12:14:23.087 に答える
-1

$_SERVER['REQUEST_URI']の解析で機能します

于 2012-04-10T12:12:01.470 に答える