.htaccess 如何获取子目录中Slim应用程序的根URL?
我必须用PHP制作一个网站,我选择使用Slim和Twig。但我的上司不希望我使用虚拟主机。因此,当我使用MAMP测试网站时遇到了问题,因为该网站位于子目录中,如.htaccess 如何获取子目录中Slim应用程序的根URL?,.htaccess,twig,mamp,slim,subdirectory,.htaccess,Twig,Mamp,Slim,Subdirectory,我必须用PHP制作一个网站,我选择使用Slim和Twig。但我的上司不希望我使用虚拟主机。因此,当我使用MAMP测试网站时遇到了问题,因为该网站位于子目录中,如http://localhost:8888/subdir 当我尝试访问资产时,我不能使用绝对路径,因为它会迫使我写入/subpath/path/to/asset。但是当我们部署应用程序时,将没有子路径。我如何才能像有虚拟主机一样为网站建立根目录 您可以在下面看到我的一些代码: index.php <?php require 'ven
http://localhost:8888/subdir
当我尝试访问资产时,我不能使用绝对路径,因为它会迫使我写入/subpath/path/to/asset
。但是当我们部署应用程序时,将没有子路径。我如何才能像有虚拟主机一样为网站建立根目录
您可以在下面看到我的一些代码:
index.php
<?php
require 'vendor/autoload.php';
include 'database.php';
use app\controller\ConfigController;
$app = new \Slim\Slim();
$app->get('/', function () {
echo "accueil";
})->name("root");
$app->group('/Admin', function () use ($app) {
$app->get("/", function (){
$ctrl = new ConfigController();
$ctrl->index();
})->name("indexAdmin");
});
配置控制器(调用函数)
模板由细枝环境调用
<!doctype html>
<html lang="fr">
<head>
<link rel="stylesheet" type="text/css" href="/app/assets/stylesheets/{{ css }}">
</head>
<body>
[...]
[...]
当我在Google上搜索和Stack Overflow时,每个人都说要创建一个虚拟主机,但我不能。是否还有其他解决方案?如果您正在编写的应用程序中使用集成Twig,则可以将该包中的TwigeExtension
添加到您的Twig实例中,并对您的资产使用siteUrl
功能。这样:
<link rel="stylesheet" href="{{ siteUrl('path/to/asset/style.css') }}">
如果您正在编写的应用程序中使用集成Twig,则可以将该包中的TwigExtension
添加到您的Twig实例中,并对您的资产使用siteUrl
功能。这样:
<link rel="stylesheet" href="{{ siteUrl('path/to/asset/style.css') }}">
Hey@Amanite,欢迎来到S.O.您是否使用
slim/views
软件包将Twig集成到您的应用程序中?Hey@Amanite,欢迎来到S.O.您是否使用slim/views
软件包将Twig集成到您的应用程序中?非常感谢ypu vert!我将在周一尝试thqt(周末我无法访问该项目)非常感谢ypu!我将在周一尝试thqt(周末我无法访问该项目)
<link rel="stylesheet" href="{{ siteUrl('path/to/asset/style.css') }}">
function siteUrl($url) {
$req = Slim::getInstance()->request();
$uri = $req->getUrl() . $req->getRootUri();
return $uri . '/' . ltrim($url, '/');
}