Jump to content

links in codeigniter


I-AM-OBODO

Recommended Posts

You might want to be more specific. Adding a link is as simple as adding the html to your view.

 

This is my header.php file and how i linked it. its not linking to the page:

<div align="center"><a href="<?php  echo('index.php/home') ?>">Home</a>   <a href="<?php anchor('index.php/about') ?>">About</a>   <a href="#">Company</a>   <a href="#">Tutorials</a> </div>

 

pls how do i resolve this? i used two methods there; the echo and anchor but to no avail

 

thanks

Link to post
Share on other sites

<?php echo anchor('target_controller/method', 'anchor text'); ?>

 

So your code:

<div align="center">
<a href="<?php  echo('index.php/home') ?>">Home</a>   
<a href="<?php anchor('index.php/about') ?>">About</a>   
<a href="#">Company</a>   
<a href="#">Tutorials</a> 
</div>

Should look like this:

<div align="center">
<?php echo anchor('home', 'Home'); ?>   
<?php echo anchor('about', 'About'); ?>   
<a href="#">Company</a>   
<a href="#">Tutorials</a> 
</div>

 

 

I left in the html tags for the # links, because CI will parse those as natural links when you use the anchor function.

 

Also, you do not need to indicated 'index.php' as that is already configured in your config/routes.php setup, and links are created by pointing to the controller.

 

Link to post
Share on other sites

<?php echo anchor('target_controller/method', 'anchor text'); ?>

 

So your code:

<div align="center">
<a href="<?php  echo('index.php/home') ?>">Home</a>   
<a href="<?php anchor('index.php/about') ?>">About</a>   
<a href="#">Company</a>   
<a href="#">Tutorials</a> 
</div>

Should look like this:

<div align="center">
<?php echo anchor('home', 'Home'); ?>   
<?php echo anchor('about', 'About'); ?>   
<a href="#">Company</a>   
<a href="#">Tutorials</a> 
</div>

 

 

I left in the html tags for the # links, because CI will parse those as natural links when you use the anchor function.

 

Also, you do not need to indicated 'index.php' as that is already configured in your config/routes.php setup, and links are created by pointing to the controller.

 

 

Thank you very very much Mahngiel. Its been solved. I altered my config file and that caused a major problem even after i have used the format you provided.

On the config file,  $config['base_url'] = 'localhost'; and here i had $config['index_page'] = 'home.php';

but on seeing the error it gave me i knew there was a problem from there so i changed: $config['base_url'] = ''; and $config['index_page'] = 'index.php'; and it did the magic plus the format you showed me.

thanks a zillion dozen times

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.