2012-08-24 3 views
3

Codeigniter URL에 문제가 있습니다.Codeigniter 이미지 및 소스 URL

<?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": 나는 컨트롤러 "welcome.php"가 나는이 사용하는 매개 변수와 함께 컨트롤러 기능 'DOR'를 액세스하려면

<!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> 

:

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

및 작동하지만 문제는 이미지가로드되지 않습니다. 나는 webroot 폴더, 'application'폴더, 심지어 'views'폴더에 이미지 파일을 저장하려고 시도했다. 하지만 여전히 이미지를로드 할 수 없습니다. 이미지 파일을 어디에 두어야합니까?

+0

자산 폴더 나 CSS 폴더, 다음 ('자산/fragor.jpg') SITE_URL에 같은 SITE_URL의 연료 소모량을 사용; – Rooster

답변

4

웹 루트 (index.php가있는 폴더)에/images/디렉토리를 만들고 base_url() 함수를 사용하여 이미지 (I.E.)에 대한 링크를 만드는 것이 가장 좋습니다.

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

오토로더 또는 수동으로 site_url() 또는 base_url()을 사용하기 전에 하나의 URL 헬퍼를로드하는 것을 잊지 마십시오.

CodeIgniter의 다시 쓰기 규칙을 사용하여 URL에서 index.php를 제거하는 경우 (다시 보이지 않는 것처럼),/images/디렉토리를 다시 작성하지 않도록하십시오 .

+0

문제는 내가 dreamweaver를 사용하여 웹을 디자인했기 때문입니다. ""을 사용하여 사이트를 변경하면 내 페이지에서 많은 URL 링크를 변경해야한다는 것을 의미합니다. URL 링크를 변경하지 않고 다른 솔루션이 있습니까? –

1

는 CodeIgniter의에서

echo img('images/gautam.gif'); 

이보기 파일에 넣고 같은 ... 이미지를 표시하는 특정 방법이 당신은 당신이 비록 루트

0

에서 "이미지"폴더를 생성해야 자동로드 설정에서 CI 도우미 'html'을 추가해야하지만,이 작업은 쉬운 일입니다.

<?php 
$image_properties = array(
    'src' => 'images/picture.jpg', 
    'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time', 
    'class' => 'post_images', 
    'width' => '200', 
    'height'=> '200', 
    'title' => 'That was quite a night', 
    'rel' => 'lightbox' 
); 
img($image_properties); 
?> 
/* <img src="site.com/index.php/images/picture.jpg" alt="Me, demonstrating how to eat 4 slices of pizza at one time" class="post_images" width="200" height="200" title="That was quite a nigh`enter code here`t" rel="lightbox" />*/ 

또는 단순한 :

<?php 
echo img('images/picture.jpg'); ?> 
// gives <img src="site.com/images/picture.jpg" />