Solution 1 :

If you are adding the <?=base_url();?>to your image, and any other path, you’ll be good.

In case you are adding variables to your function you will have the same problem all over again.

For example your image should look like this:

<img src="<?=base_ur();?>assets/img/demo/avatar1.jpg">

Hope this helps.

Solution 2 :

I would say you are using relative paths for your CSS and/or Javascript files without the base_url() in front.
Are you getting any 404s in the developer tools? They usually tell you where the problem is.

A correct way of embedding JS & CSS would be:

<link rel="stylesheet" href="<?=base_url();?>/assets/css/bootstrap.min.css">
<script src="<?=base_url();?>assets/js/bootstrap.min.js"></script>

Solution 3 :

AnPS: So I was able to solve at least part of the problem like this:

The offending code was:

<img src="assets/img/demo/avatar1.jpg"> 

It would generate the following error:

GET http://localhost/Mywebsite/private_area/assets/img/demo/avatar1.jpg 404 (Not Found) 

As it was reading the Controller – “Private_area” as a folder, so I just added ../ to the offending code

<img src="../assets/img/demo/avatar1.jpg"> 

I fixed the Toggle Buttons using a similiar approach by adding ../ to the script like this:

<script src="../assets/js/plugins.min.js"></script>
    <script src="../assets/js/app.min.js"></script>

This worked, but did I do it right? Or is this just a bad “work-around”?

Problem :

So when I load a view like this:

Address bar reads:


the view is called from the index function of the controller “private_area”, and it works fine. However when I call the page using a function “profile” such that the address bar reads:


the view loses certain functionality such as the toggle buttons dont work, and the src= doesnt work either. The code for the index function and profile function is identical.

Very confused, any ideas?

Here is some related code:

Controller “Login” Redirects using:

redirect ('private_area');

This calls route

$route['private_area'] = 'private_area';

This calls controller Private Area/Index which has the following code:

    $profiledata["fetch_profiledata"] = $this->Profiles_model->fetch_profiledata();    
    $this->load->view('pages/page-profile', $profiledata);

This works fine and displays the Page-profile view perfectly.

But if I go to another view, and then come back to Page-profile view using

    <a href="<?php echo base_url(); ?>private_area/profile" role="button">Profile</a>

Which call controller “Private_area” and function “Profile”

    function profile() 
        $profiledata["fetch_profiledata"] = $this->Profiles_model->fetch_profiledata();  
        $this->load->view('pages/page-profile', $profiledata);

The main view loads, but the src tags dont work, neither do the toggle buttons.


Comment posted by Kevin K

Thanks @renegade999, but that isnt it. Here is JS and CSS pretty much identical to what you suggested.

Comment posted by renegade999

Have you checked if any of the embedded JS files is not being loaded correctly with the developer tools. It just sounds very much like a file is not loaded corretly.


Leave a Reply

Your email address will not be published. Required fields are marked *