我有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图片和源网址
发布评论