非常に単純な MVC フレームワークをまだ見つけていません。フレームワークはどのようにして URL だけでコントローラにアクセスできるようにするのですか? と関係があると思いますが、QUERY_STRING
あると思われません?
か?
http://localhost/public/controllername
次の場所にlocalhost/public
あります。
C:\wamp\www\public\
index.php を含む
非常に単純な MVC フレームワークをまだ見つけていません。フレームワークはどのようにして URL だけでコントローラにアクセスできるようにするのですか? と関係があると思いますが、QUERY_STRING
あると思われません?
か?
http://localhost/public/controllername
次の場所にlocalhost/public
あります。
C:\wamp\www\public\
index.php を含む
一般に、これは.htaccess
書き換え ( Apache mod_rewrite )を使用して行われます。
.htaccess
書き換えを使用して、静的ファイルではないすべてのクエリをメイン エントリ ポイントに送信します。たとえばindex.php
、PHP をサーバー側言語として使用するとします。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.
もちろん、これは簡単で大まかな例にすぎませんが、これを行う方法のアイデアを提供する必要があります。
$_SERVER['REQUEST_URI']の解析で機能します