For instance, I have two applications: 'frontend' and 'backend'. I'd like my /web directory to be set up so that '/web/frontend' serves the 'frontend' assets, and '/web/backend' serves the 'backend' assets without having to go modify all the image paths, etc.
例如,我有两个应用程序:'frontend'和'backend'。我想设置我的/ web目录,以便'/ web / frontend'服务'前端'资产,'/ web / backend'服务'后端'资产,而不必修改所有图像路径,等等
1 个解决方案
#1
From the Symfony Documentation, doing this in each app's config.php should work [example is showing apps/backend/config/config.php]
从Symfony文档中,在每个应用程序的config.php中执行此操作应该可以[示例显示apps / backend / config / config.php]
sfConfig::add(array(
'sf_web_dir' => SF_ROOT_DIR.'/web/backend',
'sf_upload_dir' => SF_ROOT_DIR.'/web/backend'.sfConfig::get('sf_upload_dir_name'),
));
For some reason, this method doesn't work. If you take a look at all the variables defined inside sfConfig, you'll notice that you have to change more than sf_web_dir and sf_upload_dir to get things working.
出于某种原因,此方法不起作用。如果你看看sfConfig中定义的所有变量,你会注意到你必须更改sf_web_dir和sf_upload_dir以使事情正常工作。
One option would be to manually override the all variables inside sfConfig that point to the web directory inside each app's config.php. To see a list of all the variables, try
一种选择是手动覆盖sfConfig中指向每个应用程序的config.php中的web目录的所有变量。要查看所有变量的列表,请尝试
<?php echo var_dump(sfConfig::getall()); ?>
Your other option (The way I've done it before) would be to do it in the Apache configuration. Your virtual host settings for backend would look something like
你的另一个选择(我以前做过的方式)就是在Apache配置中做到这一点。您的后端虚拟主机设置看起来像
<VirtualHost *>
ServerName backend.dev
DocumentRoot "PATH_TO_SYMFONY_PROJECT/web/backend"
DirectoryIndex index.php
Alias /sf /usr/local/lib/php/data/symfony/web/sf
<Directory "/usr/local/lib/php/data/symfony/web/sf">
AllowOverride All
Allow from All
</Directory>
<Directory "PATH_TO_SYMFONY_PROJECT/web/backend">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Then you will need to copy backend.php, backend_dev.php [ and possibly index.php if backend is your default enviroment ] to /web/backend, and in each one of those files, change
然后,您需要将backend.php,backend_dev.php [以及可能的index.php,如果后端是您的默认环境]复制到/ web / backend,并在每个文件中进行更改
define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/..'));
to
define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/../..'));
and you should be good. I prefer this method, but if you don't have virtual hosts setup, you might not have this option.
你应该好。我更喜欢这种方法,但如果您没有设置虚拟主机,则可能没有此选项。
#1
From the Symfony Documentation, doing this in each app's config.php should work [example is showing apps/backend/config/config.php]
从Symfony文档中,在每个应用程序的config.php中执行此操作应该可以[示例显示apps / backend / config / config.php]
sfConfig::add(array(
'sf_web_dir' => SF_ROOT_DIR.'/web/backend',
'sf_upload_dir' => SF_ROOT_DIR.'/web/backend'.sfConfig::get('sf_upload_dir_name'),
));
For some reason, this method doesn't work. If you take a look at all the variables defined inside sfConfig, you'll notice that you have to change more than sf_web_dir and sf_upload_dir to get things working.
出于某种原因,此方法不起作用。如果你看看sfConfig中定义的所有变量,你会注意到你必须更改sf_web_dir和sf_upload_dir以使事情正常工作。
One option would be to manually override the all variables inside sfConfig that point to the web directory inside each app's config.php. To see a list of all the variables, try
一种选择是手动覆盖sfConfig中指向每个应用程序的config.php中的web目录的所有变量。要查看所有变量的列表,请尝试
<?php echo var_dump(sfConfig::getall()); ?>
Your other option (The way I've done it before) would be to do it in the Apache configuration. Your virtual host settings for backend would look something like
你的另一个选择(我以前做过的方式)就是在Apache配置中做到这一点。您的后端虚拟主机设置看起来像
<VirtualHost *>
ServerName backend.dev
DocumentRoot "PATH_TO_SYMFONY_PROJECT/web/backend"
DirectoryIndex index.php
Alias /sf /usr/local/lib/php/data/symfony/web/sf
<Directory "/usr/local/lib/php/data/symfony/web/sf">
AllowOverride All
Allow from All
</Directory>
<Directory "PATH_TO_SYMFONY_PROJECT/web/backend">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
Then you will need to copy backend.php, backend_dev.php [ and possibly index.php if backend is your default enviroment ] to /web/backend, and in each one of those files, change
然后,您需要将backend.php,backend_dev.php [以及可能的index.php,如果后端是您的默认环境]复制到/ web / backend,并在每个文件中进行更改
define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/..'));
to
define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/../..'));
and you should be good. I prefer this method, but if you don't have virtual hosts setup, you might not have this option.
你应该好。我更喜欢这种方法,但如果您没有设置虚拟主机,则可能没有此选项。