Welcome Guest, Not a member yet? Register   Sign In
Using base_url in a view
#1

[eluser]montanaflynn[/eluser]
Maybe I am missing something but I am having trouble echoing the base_url as defined in the config.php in a view. How would you go about doing this? I have tried adding
Code:
<?php echo $base_url;?>
in the view but it gives an error "Message: Undefined variable: base_url"


Some background info:

This is my first time using a PHP framework and I have decided to convert my static site to Codeignitor. This is what I have done so far:

Filled out the system/config/config.php file & routes.php to make home.php the default controller.

Created a home.php controller with the following:
Code:
<?php

    class Home extends Controller {
    function index()
    {
        $data['title'] = "This is the page title";
            $data['desc'] = "My site description is complete!";
            $this->load->view('homeView', $data);
    }
    }
?>


Created a homeView.php view with the following (simplyfied):

Code:
<!DOCTYPE html>
&lt;html&gt;
&lt;head&gt;

  &lt;title&gt;&lt;?php echo $title;?&gt;&lt;/title&gt;
  &lt;meta name="description" content="&lt;?php echo $desc;?&gt;" /&gt;

  &lt;style src="&lt;?php echo $base_url;?&gt;/css/style.css" type="text/css"&gt;
  [removed]
&lt;/head&gt;
&lt;body&gt;
<h1>&lt;?php echo $title;?&gt;</h1>
&lt;/body&gt;
&lt;/html&gt;

Everything works except the base_url, I have a feeling I need to define it in the controller. Any suggestions?


Messages In This Thread
Using base_url in a view - by El Forum - 09-01-2009, 06:53 PM
Using base_url in a view - by El Forum - 09-01-2009, 08:07 PM
Using base_url in a view - by El Forum - 09-01-2009, 08:40 PM
Using base_url in a view - by El Forum - 09-01-2009, 08:45 PM
Using base_url in a view - by El Forum - 09-01-2009, 08:47 PM
Using base_url in a view - by El Forum - 09-01-2009, 08:57 PM
Using base_url in a view - by El Forum - 09-01-2009, 09:11 PM
Using base_url in a view - by El Forum - 09-02-2009, 01:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB