それを行うには多くの方法があります。
私の意見では、Asseticはコンピューティングパフォーマンスの無駄であり、この単純な問題には非常に適していません。
前述のように、問題はモジュールから/publicにアクセスすることです。
私の解決策は次のとおりです。
htdocs / yoursite / public / .htaccessを編集して、RewriteEngineOnの直後にこの行を追加します。
RewriteRule ^resource/([a-zA-Z0-9\.\-]+)/([a-zA-Z0-9\.\-_\/]+)$ index.php?action=resource&module=$1&path=$2 [QSA,L]
htdocs / yoursite / public / index.phpを編集し、chdir(dirname( DIR));の直後にこのコードを追加します。
if (isset($_GET['action']) && $_GET['action'] == "resource") {
$module = $_GET['module'];
$path = $_GET['path'];
if (!ctype_alnum($module))
die("Module name must consist of only alphanumeric characters");
$filetype = pathinfo($path, PATHINFO_EXTENSION);
$mimetypes = array(
'js' => "text/javascript",
'css' => "text/css",
'jpg' => "image/jpeg",
'jpeg' => "image/jpeg",
'png' => "image/png"
);
if (!isset($mimetypes[$filetype]))
die(sprintf("Unrecognized file extension '%s'. Supported extensions: %s.", htmlspecialchars($filetype, ENT_QUOTES), implode(", ", array_keys($mimetypes))));
$currentDir = realpath(".");
$destination = realpath("module/$module/public/$path");
if (!$destination)
die(sprintf("File not found: '%s'!", htmlspecialchars("module/$module/public/$path", ENT_QUOTES)));
if (substr($destination, 0, strlen($currentDir)) != $currentDir)
die(sprintf("Access to '%s' is not allowed!", htmlspecialchars($destination, ENT_QUOTES)));
header(sprintf("Content-type: %s", $mimetypes[$filetype]));
readfile("module/$module/public/$path", FALSE);
die();
}
使用法:/ resource / moduleName / path
例:
http: //yoursite.com/resource/Statistics/css/style.cssは、yoursite / module / Statistics / public / css/style.cssから実際のcssを読み取ります。
高速で安全であり、構成でパスを指定する必要がなく、インストールも必要なく、サードパーティのメンテナンスに依存せず、ビューにヘルパーも必要ありません。どこからでも/resourceにアクセスするだけです!楽しみ :)