I-AM-OBODO Posted March 15, 2012 Share Posted March 15, 2012 hi, pls how can I add links in codeigniter? do I need to create a method in the controller? I have a header that contains navigation with links. thanks Link to comment https://forums.phpfreaks.com/topic/259014-links-in-codeigniter/ Share on other sites More sharing options...
trq Posted March 16, 2012 Share Posted March 16, 2012 You might want to be more specific. Adding a link is as simple as adding the html to your view. Link to comment https://forums.phpfreaks.com/topic/259014-links-in-codeigniter/#findComment-1327932 Share on other sites More sharing options...
I-AM-OBODO Posted March 16, 2012 Author Share Posted March 16, 2012 on the header I have a couple of navigation: home about. contact. etc. how do I link them to corresponding pages. Link to comment https://forums.phpfreaks.com/topic/259014-links-in-codeigniter/#findComment-1327940 Share on other sites More sharing options...
trq Posted March 16, 2012 Share Posted March 16, 2012 See my previous reply. Link to comment https://forums.phpfreaks.com/topic/259014-links-in-codeigniter/#findComment-1328001 Share on other sites More sharing options...
Mahngiel Posted March 18, 2012 Share Posted March 18, 2012 Reading the CI docs is a great way to learn stuff. What you're looking for in this case is the anchor() function. Link to comment https://forums.phpfreaks.com/topic/259014-links-in-codeigniter/#findComment-1328672 Share on other sites More sharing options...
I-AM-OBODO Posted March 19, 2012 Author Share Posted March 19, 2012 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 comment https://forums.phpfreaks.com/topic/259014-links-in-codeigniter/#findComment-1328882 Share on other sites More sharing options...
Mahngiel Posted March 19, 2012 Share Posted March 19, 2012 <?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 comment https://forums.phpfreaks.com/topic/259014-links-in-codeigniter/#findComment-1328890 Share on other sites More sharing options...
I-AM-OBODO Posted March 19, 2012 Author Share Posted March 19, 2012 <?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 comment https://forums.phpfreaks.com/topic/259014-links-in-codeigniter/#findComment-1328939 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.