Codeigniter图片和源网址

编程入门 行业动态 更新时间:2024-10-16 20:28:47
本文介绍了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图片和源网址

本文发布于:2023-10-31 13:27:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546219.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网址   图片   Codeigniter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!