0

I parsed a html into Header, Sidebar, Content, Footer etc.. And main view put together.. It is working when I calling view from mycontroller/index but it isnt working when I calling view from mycontroller/method.. Pseude Code below;

Controller;

class welcome extends CI_Controller{
   public function index(){
      $data['content'] = "**main**_page";
      $this->load->view('welcome_message',$data);
   }

   public function deneme(){
      $data['content'] = "**another**_page";
      $this->load->view('welcome_message',$data);
   }
}

View;

<html>
  <head>
    <?php $this -> load -> view("includes/head_view");?>
  </head>
  <body>
    <?php $this -> load -> view("includes/navbar_view");?>
    <?php $this -> load -> view($content);?>
    <?php $this -> load -> view("includes/footer_view"); ?>
  </body>
 </html>

Example Sub View

<img src="<?php base_url(); ?>assets/img/image1.jpg">

When I open below address, everything working fine, images loading

http://localhost/myproject

But When open below, images is not loading

http://localhost/myproject/welcome/deneme

I check the images url from Google Chrome> Page Source Code.. The link writing like that; localhost/myproject/welcome/assets/img/image1.jpg

instead of

localhost/myproject/assets/img/image1.jpg

It's adding controller name to all links how can resolve it Thank you

2
  • what is your base_url in config? Commented Aug 12, 2018 at 16:18
  • $config['base_url'] = 'localhost/myproject'; Commented Aug 12, 2018 at 16:36

1 Answer 1

1

Where you define your base_url it says "URL to your CodeIgniter root. Typically this will be your base URL, WITH a trailing slash":

$config['base_url'] = 'http://localhost/myproject/';
Sign up to request clarification or add additional context in comments.

6 Comments

Still same.. This is adding "welcome" string to paths.. localhost/myproject/welcome/assets/img/image1.jpg
That isn't the default behavior. Is your localhost actually like localhost:8080 or something?
I checked, not :(
try: <?php echo base_url("/assets/img/image1.jpg"); ?>
you need to echo and make sure url_helper is loaded
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.