Shashi Roy
Shashi Roy

Reputation: 333

Dynamically accessed URL is not the same url stored in the database in CodeIgniter

I am creating a cms where an user can upload an url with title. These URLs and titles, I am accessing dynamically in my front page of the website. Suppose if I uploaded an url : www.google.com and title : google; then my front page displays the url : http://localhost/project/index.php/www.google.com and title : google

This is the foreach loop which I am running in my view page to display the url and title.

 <?php foreach($links as $a) { ?>
        <a href="<?php echo $a -> url; ?>" class="quicklinks"><b><?php echo $a -> url_title; ?></b></a>
 <?php } ?>

where echo $a -> url; is pointing to the URL column in the table and echo $a -> url_title; is pointing to the url title column of the table. I am using datampper for the DB Coding. Please help me to display only www.google.com . Thank you so much in advance.

Upvotes: 1

Views: 160

Answers (1)

Aidas
Aidas

Reputation: 1249

Just add 'http://' in front of stored URL (if it doesn't contain this) or ammend your script to add 'http://' (or 'https://') to a submited link before inserting it into database.

For this you may utilize CodeIgniter's prep_url() function from URL helper:

http://codeigniter.com/user_guide/helpers/url_helper.html

Upvotes: 1

Related Questions