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

[eluser]Unknown[/eluser]
Hi there, I'm new using CI to do web programming. I have a hard time to redirect my home page to another page. I have read some discussion of using base_url but still I can not find a way.
here is the code

I have configure the base url in config.php
$config['base_url']= 'http://localhost/arvindo/';

autoload the helper
$autoload['helper'] = array('html','url');

here is the controller of home

class Home extends CI_Controller {


function index()
{
$this->load->view('temp_header');
$this->load->view('home');
$this->load->view('temp_nav');


}
}

I try to test the menu list:
Code:
<li><a href="&lt;?php echo base_url();?&gt;home"> Home</a></li>

but the output is

Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.
Error 404
localhost
Apache/2.4.2 (Win32) OpenSSL/1.0.1c PHP/5.4.4

Can somebody help me please?
sorry if my writing skill is not good Smile
#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:
&lt;?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
#3

[eluser]Unknown[/eluser]
Thanks, it's working Smile




Theme © iAndrew 2016 - Forum software by © MyBB