Welcome Guest, Not a member yet? Register   Sign In
View loses the path as the case of the controller call
#1

(This post was last modified: 04-06-2015, 11:49 AM by smallbug.)

Hi All!

I'm using the controller:

PHP Code:
public function test() {
 
$this->load->view('messages_view');


to call the view-page "messages_view.php", which shows a picture:

Code:
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>CodeIgniter!</title>
    </head>
    

    <body>
        <div>
            <img src="../../image/app/mypic.jpg"  />
        </div>
    </body>
</html>

By sending: http://localhost/testproject/index.php/employee/test/
It works fine!

But if I have transfer parameters like:

PHP Code:
public function test($var1$var2) {
 
// ...
 
$this->load->view('messages_view');


By sending: http://localhost/testproject/index.php/e...e/test/1/2


the messages_view.php loses the path to the picture! It seems that the deep of the path depends on the amount of the called transfer parameters.

How could I resolve this situation?
Reply
#2

Don't use a relative path, with "../.." stuff. That means it's looking down from the 2 dirs from the CURRENT url, so if you have more parameters in the url it looks in the wrong location!
Load the url helper (autoload) and use base_url(), like:
PHP Code:
<img src="<?php echo base_url('image/app/mypic.jpg'); ?>"  /> 

will produce
http://yoursite.com/image/app/mypic.jpg
for the image src
Reply
#3

Thanks a lot! That's what I am looking for!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB