Welcome Guest, Not a member yet? Register   Sign In
help!!! base_url unable to rediret to another page
#2

[eluser]Ed Robindon[/eluser]
Hi,

The controller functions are not available to the view. You can, however,
pass the baseurl to the view in an array of data.

Here's a simple test controller:
Code:
<?php
/**
* 9-29-2012
* General testing controller
* test.php in controllers
* Uses the view test_view.php in views
*/
class test extends CI_Controller
{
  function __construct()
  {
    parent::__construct();
  }
  
  public function index()
  {
    //Pass some variables to the view
    $data['date'] = date('m/d/Y');
    $data['timex'] = date('h:i:s');
    //Get the base url for use by the view
    $data['baseurl'] = $this->config->item('base_url');
    $this->load->view('test_view', $data);
  }
}

And the view:
Code:
<!DOCTYPE html>
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;CI Testing View&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<p>
The current date is &lt;?php echo $date ?&gt;
</p>
<p>
The current time is &lt;?php echo $timex ?&gt;
</p>
<p>
Our base url is &lt;?php echo $baseurl ?&gt;
</p>
<a href="welcome">Home page no baseurl</a> Works without baseurl or htaccess<br/>
<a href="&lt;?php echo $baseurl.'welcome'?&gt;">Home with baseurl</a> Needs an htaccess or index.php added into the url<br/>
<a href="&lt;?php echo $baseurl.'index.php/welcome'?&gt;">Home with baseurl</a> Should work either way
<p>All 3 work wth the htaccess in place</p>
&lt;/body&gt;
&lt;/html&gt;
Here's my htaccess:
Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Hope this gets you going...
Ed


Messages In This Thread
help!!! base_url unable to rediret to another page - by El Forum - 09-28-2012, 08:32 AM
help!!! base_url unable to rediret to another page - by El Forum - 09-29-2012, 05:16 PM
help!!! base_url unable to rediret to another page - by El Forum - 09-29-2012, 08:51 PM



Theme © iAndrew 2016 - Forum software by © MyBB