0

I have a url like this

localhost/codeIgniter/Depan?lang=id

and I want to make it like this

localhost/codeIgniter/id/Depan

where localhost/codeIgniter is the base_url, /id is parameter for language, and /Depan is the controller name. But since I change the url as the second one. The base_url is changed to localhost/codeIgniter/id. So everytime I pass images location like assets/image/pic1.jpg from javascript. The link in html become localhost/codeIgniter/id/assets/image/pic1.jpg. And the file that actually stored in codeIgniter/assets/images folder is can't accessed. Ive already set the

$config['base_url'] = 'localhost/codeIgniter'

I wish I could use the second url without changing the base url

HTML

 <div class="picture container">
  <img id="slide" src="">
  
  <div class="desc">
   <div id="text">
    <p></p>
   </div>

   <div id="text">
   </div>
  </div>

  <div onclick="prev()" class="prev">
   <img src="<?php echo base_url();?>assets/button/prev.png">
  </div>

  <div onclick="next()" class="next">
   <img src="<?php echo base_url();?>assets/button/next.png">
  </div>

  <div class="pics">
  </div>
  
  <script> var sldrpic = <?php echo json_encode($sldrpic); ?>;</script>
  <script src="<?php echo base_url();?>javascript/sldr_home.js"></script>

 </div>

Javascript

function firstslide() {
 if (!document.images)
  return
 document.getElementById('slide').src = slideimages[step].src;
 document.getElementById('slide').alt = sldrpic[step].nama;

 document.getElementById('text').childNodes[1].innerHTML = sldrpic[step].nama;
}

with the javascript I want to pass the slideimages[] array that contain folder path assets/image/pic.jpg to the

<img id="slide" src="">

estu
  • 117
  • 1
  • 3
  • 9
  • keep url `localhost/codeIgniter/Depan/id` is easier. Have you removed `index.php` from url part using .htaccess? Please post your html if possible. – jagad89 Jun 12 '15 at 09:34
  • I've removed `index.php` using .htaccess. I post it above (edited) – estu Jun 12 '15 at 13:44
  • can you do something link `document.getElementById('slide').src = slideimages[step].src;` in javascript section. – jagad89 Jun 12 '15 at 13:52
  • I've tried make a `var base_url = window.location.origin` and the script become `document.getElementById('slide').src = base_url()+slideimages[step].src` but the path in the html become `localhost/localhost/codeIgniter/id/assets/image/pic.jpg` – estu Jun 12 '15 at 14:02

1 Answers1

0

I have put base url variable in html as shown below.

 <div class="picture container">
  <img id="slide" src="">
  
  <div class="desc">
   <div id="text">
    <p></p>
   </div>

   <div id="text">
   </div>
  </div>

  <div onclick="prev()" class="prev">
   <img src="<?php echo base_url();?>assets/button/prev.png">
  </div>

  <div onclick="next()" class="next">
   <img src="<?php echo base_url();?>assets/button/next.png">
  </div>

  <div class="pics">
  </div>
  
  <script> var sldrpic = <?php echo json_encode($sldrpic); ?>;</script>

        // echo base url from php
  <script> var base_url ="<?php echo base_url();?>"; </script>

  <script src="<?php echo base_url();?>javascript/sldr_home.js"></script>
 </div>

javascript

function firstslide() {
    if (!document.images)
        return
    // note: base_url is variable. not function.
    document.getElementById('slide').src = base_url + slideimages[step].src;
    document.getElementById('slide').alt = sldrpic[step].nama;

    document.getElementById('text').childNodes[1].innerHTML = sldrpic[step].nama;
}
jagad89
  • 2,603
  • 1
  • 24
  • 30
  • the link in html become `localhost/codeIgniter/http://localhost/codeIgniter/id/assets/image/pic.jpg` (the base_url doubled) the image still doesn't show – estu Jun 12 '15 at 14:19
  • Oh!! that means you have `slideimage[step].src = 'http://localhost/codeIgniter/id/assets/image/pic.jpg'`. That's where the bug introduce . – jagad89 Jun 12 '15 at 14:22
  • yea but in database it only contain `assets/image/pic.jpg` i've tried to ` $value) { echo $value['sldrpic']; } ?>` to echo the array in html and the output is `assets/image/pic.jpg` so I think the problem come when the array passed from javascript to html. but I dont know why It's happened – estu Jun 12 '15 at 14:26
  • plz join me [here](https://chat.stackoverflow.com/rooms/info/80404/image-problem-with-septi?tab=general) – jagad89 Jun 12 '15 at 14:33
  • I have joined there. but I can't chat cuz of low reputation – estu Jun 12 '15 at 15:10
  • Wish to solve this problem. . not possible with comments :-( – jagad89 Jun 12 '15 at 18:17