我在新应用中使用了旧的网站设计代码。问题是我没有使用HTML帮助程序来加载图像。我正在使用HTML图像标签<img style="width:95px; margin-top:20px;"src="images/logo.png" />
。在此链接http:// localhost / dashboard / dboard /中正常工作,但在此链接http:// localhost / dashboard / dboard / pages / demo中无效。Pages是控制器,而demo是控制器中的方法。
我的PagesController
样子是这样的:
namespace App\Controller;
use Cake\Core\Configure;
use Cake\Network\Exception\NotFoundException;
use Cake\View\Exception\MissingTemplateException;
class PagesController extends AppController
{
public function display()
{
$path = func_get_args();
enter code here`enter code here`
$count = count($path);
if (!$count) {
return $this->redirect('/');
}
$page = $subpage = null;
if (!empty($path[0])) {
$page = $path[0];
}
if (!empty($path[1])) {
$subpage = $path[1];
}
$this->set(compact('page', 'subpage'));
try {
$this->render(implode('/', $path));
} catch (MissingTemplateException $e) {
if (Configure::read('debug')) {
throw $e;
}
throw new NotFoundException();
}
}
public function demo()
{
}
public function contactus()
{
}
public function downloads()
{
}
}
我的.htaccess文件如下所示:-
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
重要的是我将所有图像都放在这里:C:\ xampp \ htdocs \ dashboard \ dboard \ webroot。我正在使用CakePHP 3.0。
输出看起来像这样:
问题在于,apache尝试在路径中搜索图像,<app_folder>/webroot/pages/dashboard/images
因为您可能会查看是否在Web开发人员控制台中检查了404错误(在Chrome浏览器中,按F12键)。
您可以通过以下两种方法解决:
src
像这样在基本网址前添加:<img src='<?php echo Router::url('/') ?>/images/picture.png' >
这样,最终的网址将如下所示:
http://localhost/dashboard/dboard/images/picture.png
随即会找到您的文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句