cakephp 图像助手在本地工作但不在线
cakephp Image helper works locally but not online
我在通过 cakephp 的图像助手显示图像时遇到问题。图片的 url 在数据库中存储为: companiesLogos/defaultLogo.jpg 我用来显示该图片的代码是 <?php echo $this->Html->image($user['User']['img_path'], array('class' => 'img-circle', 'style' => 'width:50px')); ?>
它在本地版本的浏览器中呈现为 <img src="/websites/Gimble/img/companiesLogos/defaultLogo.jpg" class="img-circle" style="width:50px" alt="">
其中 url 是 http://localhost:8080/websites/websitename/DashBoard
它在浏览器中呈现为在线版本 <img src="/img/companiesLogos/defaultLogo.jpg" class="img-circle" style="width:50px" alt="">
其中 url 是 http://app.websitename.com.au/DashBoard
这里有两个环境的图片,首先是本地版本,然后是在线版本。在线版本位于 linux 服务器上,而本地版本位于 windows 计算机上。
我错过了什么?
问题很可能出在应用程序的根文件夹中(/img 不指向 cakephp 根目录,而是指向托管根目录)。在每个 .htaccess 文件(cakephp、app 和 webroot 文件夹的根目录)中,在 RewriteEngine on:
下面添加这一行
RewriteEngine On
RewriteBase /subfolder_name/
您需要使用定义文档根目录来放置您的源代码。我认为这里有很好的解释:
RewriteBase 如何在 .htaccess
中工作
我自己的话,在阅读文档和试验之后:
生产安装是一种更灵活的 CakePHP 设置方式。使用这种方法可以让整个
域充当单个 CakePHP 应用程序。这个例子将帮助你在任何地方安装 CakePHP
您的文件系统并使其在 http://www.example.com 可用。请注意,此安装可能需要
在 Apache 网络服务器上更改 DocumentRoot 的权利。
将 CakePHP 存档的内容解压到您选择的目录中。为此目的
例如,我们假设您选择将 CakePHP 安装到 /cake_install。您的生产设置看起来像
这在文件系统上:
/cake_install/
app/
webroot/ (this directory is set as the ‘‘DocumentRoot‘‘
directive)
lib/
plugins/
vendors/
.htaccess
index.php
README
使用 Apache 的开发人员应将域的 DocumentRoot 指令设置为:
DocumentRoot /cake_install/app/webroot
如果您的 Web 服务器配置正确,您现在应该可以在以下位置找到可访问的 CakePHP 应用程序
http://www.example.com.
我在通过 cakephp 的图像助手显示图像时遇到问题。图片的 url 在数据库中存储为: companiesLogos/defaultLogo.jpg 我用来显示该图片的代码是 <?php echo $this->Html->image($user['User']['img_path'], array('class' => 'img-circle', 'style' => 'width:50px')); ?>
它在本地版本的浏览器中呈现为 <img src="/websites/Gimble/img/companiesLogos/defaultLogo.jpg" class="img-circle" style="width:50px" alt="">
其中 url 是 http://localhost:8080/websites/websitename/DashBoard
它在浏览器中呈现为在线版本 <img src="/img/companiesLogos/defaultLogo.jpg" class="img-circle" style="width:50px" alt="">
其中 url 是 http://app.websitename.com.au/DashBoard
这里有两个环境的图片,首先是本地版本,然后是在线版本。在线版本位于 linux 服务器上,而本地版本位于 windows 计算机上。
我错过了什么?
问题很可能出在应用程序的根文件夹中(/img 不指向 cakephp 根目录,而是指向托管根目录)。在每个 .htaccess 文件(cakephp、app 和 webroot 文件夹的根目录)中,在 RewriteEngine on:
下面添加这一行RewriteEngine On
RewriteBase /subfolder_name/
您需要使用定义文档根目录来放置您的源代码。我认为这里有很好的解释: RewriteBase 如何在 .htaccess
中工作我自己的话,在阅读文档和试验之后:
生产安装是一种更灵活的 CakePHP 设置方式。使用这种方法可以让整个 域充当单个 CakePHP 应用程序。这个例子将帮助你在任何地方安装 CakePHP 您的文件系统并使其在 http://www.example.com 可用。请注意,此安装可能需要 在 Apache 网络服务器上更改 DocumentRoot 的权利。 将 CakePHP 存档的内容解压到您选择的目录中。为此目的 例如,我们假设您选择将 CakePHP 安装到 /cake_install。您的生产设置看起来像 这在文件系统上:
/cake_install/
app/
webroot/ (this directory is set as the ‘‘DocumentRoot‘‘
directive)
lib/
plugins/
vendors/
.htaccess
index.php
README
使用 Apache 的开发人员应将域的 DocumentRoot 指令设置为:
DocumentRoot /cake_install/app/webroot
如果您的 Web 服务器配置正确,您现在应该可以在以下位置找到可访问的 CakePHP 应用程序 http://www.example.com.