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

(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() {

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

<!DOCTYPE html>
        <meta charset="utf-8">

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

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) {
// ...

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?

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
for the image src

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

Theme © iAndrew 2016 - Forum software by © MyBB