Hi i am new in codeigniter, having trouble with link formation. In my page i have link to another page same to <li>Feed Page</li>
here feed is one of my controller . But the link is showing to me as http://localhost/BusinessPad/localhost/BusinessPad/feed ---that actually doesn't exists. Can't understand how this happen. I have make $config['index_page'] = ''; and add a .htaccess file.
check for value you have assigned to base_url in you config.php file ,try site_url(), change:
<?php base_url('feed');?>
to
<?php echo site_url('feed'); ?>
you can create your own tag and insert a url in the href like this
Link
Or if you want to helper
you can use the URL helper this way to generate an tag
anchor(uri segments, text, attributes)
So... to use it...
<?php echo anchor('controller/function/uri', 'Link', 'class="link-class"') ?>
use this:-
Link
or
Link
or
Link
use this way
Feed Page
or
Feed Page
Related
this is my code below.
<li>Why share?</li><li>
But after I apply this i manage to redirect to the page but when i try to press another page the url will be keep adding like this and cause page not found.
The page look like this
But when i try to link to home page, the url won't change back to /home only
Any solution? or another way to link the page?
Need help on this!
Thanks!
Your href should have a slash in front of it so that it goes to "root".
<li>Why share?</li><li>
If not, the browser will think it is relative to the current route. Or use Codeigniter's built-in site_url() function
<li>Why share?</li>
Read about relative/absolute here: http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/
You need to set your base_url() in config.php, and call the url_helper so that you can then use it.
Step by Step Instructions:
in application/config/config.php, set your base_url, I prefer to use something like this:
$config['base_url'] = 'http://' . $_SERVER['SERVER_NAME'] . '/';
in application/config/autoload.php, add url helper:
$autoload['helper'] = array('url');
Use it in your views like this:
<a href="<?= base_url('about/why') ?>" > link </a>
Read this: https://www.codeigniter.com/user_guide/helpers/url_helper.html
In Codeigniter, I have a database containing a link of a site.
Each item(event) has a link to the event page.
Site
But instead of going to the desired site, it just adds the link to the existing url like this: http://web.site.local/index.php/evenementen/www.referedsite.com
when checking the html code it shows the following:
Site
Does anyone know how to make it go to www.referedsite.com instead of making it add this to the existing link?
You need to put HTTP://
Site
In codeignitor you can use
echo anchor('', 'Site');
// Prints: Site
Read CI Anchor
try
Site
I am new to CodeIgniter and having trouble with link formation. In my page, I have a link to another page set to:
<li>Feed Page</li>
Here the feed is one of my controllers, but the link is showing as:
http://localhost/BusinessPad/localhost/BusinessPad/feed,
which doesn't actually exist. I can't understand how this happened; I have made sure: $config['index_page'] = ''; and I added an .htaccess file. If I leave $config['base_url']='', the base URL is still not working for me.
To deal with anchor tag, You can have like this
Feeds
You shall put the base_url inside your anchor tag and then your controller name.
Then you will get the url like localhost/BusinessPad/feed which you expect.
Note : Make sure you have loaded the url helper by $this->load->helper('url'); or loaded in autoload itself
Feed Page
if this not works use this
Feed Page
Explain :
<?php echo base_url();?>//URL
BusinessPad//Controller
feed//Function
in 1. this will give your site URL. http://localhost/BusinessPad/localhost/. if you host this to live server it will come with tour domain name.
then in 2 it will call your controller which Contains your functions.
Note: if you juct call your controller it will call automatically public function index() if you create.
then in 3 it will redirect to your function which you exactly need.
Hi, I want to redirect my page to another website, I used anchor tag but when I click on this it will add my website name also
http://au.pricecomparereview.com/www.theiconic.com.au/Rococo-Textured-Mini-Skirt-113532.html
Please tell me about this . I am new in php I am using oscommerce
www.theiconic.com.au/Rococo-Textured-Mini-Skirt-113532.html
use like this, you may be missing http://
www.theiconic.com.au
If you want a PHP approach try this:
// Declare url variable
$url = "http://www.theiconic.com.au/Rococo-Textured-Mini-Skirt-113532.html";
// Use it to create the <a> with php
echo "www.theiconic.com.au";
Or with html use the PHP assing tags:
www.theiconic.com.au
I think your anchor tag would be like this presently:
www.theiconic.com.au
Change it to
www.theiconic.com.au
and it will work fine.
I'm trying to add a page link in CakePHP using:
<?php echo $html->link('Home', '/notes/index');?>
It doesn't seem to output the proper link.
What I'd want is something like this:
Home
How can I do this?
You'll want to use a url array
<?php echo $html->link('Home', array('controller'=>'notes','action'=>'index')); ?>
This will work for you. You will not be able to use an absolute path :)
Check out the manual page, http://api.cakephp.org/class/html-helper#method-HtmlHelperlink
Create individual controller for this page or create routing for this page in PagesController.