Codeigniter图片和源网址 [英] Codeigniter Image and Source URL

查看:74
本文介绍了Codeigniter图片和源网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Codeigniter网址的问题。我有一个控制器welcome.php:

I have a problem with Codeigniter URL. I have a controller "welcome.php" :

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $data['tiung'] = 'index';
        $this->load->view('welcome_message',$data);
    }

    public function dor($bus)
    {
        $data['tiung'] = $bus;
        $this->load->view('welcome_message',$data);
    }
}

和一个视图welcome_message.php p>

and a view "welcome_message.php" :

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Welcome to CodeIgniter</title>
</head>
<body>
    sesuatu <?php echo $tiung?>
    <img src="fragor.jpg" width="720" height="246" alt=""/>
    ladalah
</body>
</html>

如果我想使用参数访问控制器函数'dor' >

If I want to access the controller function 'dor' with a parameter I used this :

localhost/hostname/index.php/welcome/dor/something

它工作,但问题是图像未加载。我试图把图像文件放在webroot文件夹,'application'文件夹,甚至在'views'文件夹。但是图像仍然无法加载。

and it works, but the problem is the image isn't loaded. I tried to put the image file in the webroot folder, 'application' folder, and even in the 'views' folder. But the image still can't load. Where should I put the image file?

推荐答案

最好的做法是在webroot中创建一个/ images /目录使用index.php文件夹)并使用 base_url()函数获取图像的链接,

The best practice for this is to create an /images/ directory in your webroot (the folder with index.php) and use the base_url() function to get the link to the image, I.E.

<img src="<?php echo base_url('images/fragor.jpg'); ?>" width="720" height="246" alt=""/>

不要忘记使用自动加载器或手动加载url帮助器,然后使用 site_url() base_url()

Don't forget to load the url helper either with the autoloader or manually before using site_url() or base_url().

使用CodeIgniter的重写规则从URL(它看起来不像你在做)中删除index.php,不要忘记从重写中排除/ images /目录。

Also if you're using CodeIgniter's rewrite rules to remove the index.php from the URL (which it doesn't look like you're doing), don't forget to exclude the /images/ directory from the rewrite.

这篇关于Codeigniter图片和源网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆