Reputation: 1564
I am building a site entirely on codeigniter .I have set my default controller as cuff. so whenever users type the domain name it takes the control to that controller.
class Cuff extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('url');
}
public function index()
{
$this->load->view('index');
}
public function navigate()
{
echo "test";
exit;
}
}
In my index view I want an anchor to navigate to a function in my default controller .
so when I write
<a href="<?php echo base_url();?>navigate">our collection</a>
, it says page not found .
I have even set the base url like this
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= preg_replace('@/+$@','',dirname($_SERVER['SCRIPT_NAME'])).'/';
Cant seem to figure out the issue.
Upvotes: 1
Views: 3552
Reputation: 28763
Simply you use
"<?php echo site_url();?>/cuff/navigate">our collection</a>
Upvotes: 0
Reputation: 527
The problem is in your routing.
Edit your routes.php (located in the folder ../application/config/) and add the code below:
$route['navigate'] = "Cuff/navigate";
For more information regarding Codeingiter URI Routing:
http://codeigniter.com/user_guide/general/routing.html
Hope this helped you.
Upvotes: 0
Reputation: 12197
Set $config['base_url'] ='';
In your .htaccess
file:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|js|css|favicon|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Make sure your controller is in controller's folder (not any subfolder) and is properly named cuff.php
Try navigating to http://yoursite/cuff/navigate
If you still see errors try rewriting the last line in .htaccess
to:
RewriteRule ^(.*)$ /index.php/$1 [L]
(without question mark).
Please tell if that helps!
EDIT: and your links better all be in this form:
<a href="<?php echo site_url('cuff/navigate');?>">Link</a>
Upvotes: 0
Reputation: 2288
You missed the controller name
<a href="<?php echo base_url();?>cuff/navigate">our collection</a>
Upvotes: 3