Welcome Guest, Not a member yet? Register   Sign In
Create Links from Database Content
#1

[eluser]TexMax007[/eluser]
Hello all, I'm new here. I love CI so far!

NOTE: I had to edit the 'links' due to a posting restriction on this forum.

Problem: News article body text is stored in MySQL. Some links need to be within the body text. These links need to be generated 'on the fly' (e.g. they aren't static). However, php links aren't parsed and evaluated when retrieved from the database.


More Details:

I'm developing a site to replace an existing site. Obviously the domain names are different right now while I'm testing. Consequently, my links I've been using are like so: <?php echo anchor('company/contact','Contact Us'); ?> or [a href="<?php echo base_url(); ?>company/contact">Contact Us[/a].

Since I need the base url part to be dynamic, I don't know how to proceed. Static links like [a href="www.google.com">google[/a] will work when retrieved from the database.


I've run across something about using the eval() function, but apparently that's slow. Would there be a different way of achieving what I'm trying to do?

Any help on this would be greatly appreciated.

Thanks guys!

Max

#2

[eluser]CroNiX[/eluser]
Ick, that's a bad situation. I wouldn't use eval() on it, but for security reasons. I would just make my links like:
Code:
<a href="/company/contact">Contact Us</a>
which will work on both sites (assuming you removed index.php from the url with htaccess, on both sites, and both sites are in the site root).
#3

[eluser]TexMax007[/eluser]
Thanks for the quick response!

I had just come back to edit my post because I was mistaken about the static links working.

I tried doing href="/company/contact" and that would work, however, right now my base url is www.mydomain.com/test/

Using this method, I get a link that goes to www.mydomain.com/company/contact when I need it to go to www.mydomain.com/test/company/contact (IN THIS CASE), but direct to www.myNEWdomain.com/company/contact when I make the switch. Hence the desire for it to process the base_url(). (my base_url right now is www.mydomain.com/test/.


For static links like href="www.google.com", it's making this: www.mydomain.com/test/currentpage/www.google.com What the heck?!

Continued assistance would be great!

EDIT: for static links, if I do href="http://www.google.com" it'll work.
#4

[eluser]CroNiX[/eluser]
in your htaccess on the dev box, try:
Code:
RewriteBase /test/
#5

[eluser]CroNiX[/eluser]
I thought of something else you could try. Maybe in your text you could code your urls like:
Code:
<a href="{base_url}company/contact">Contact Us</a>

Then, when you retrieve your results and just before you output, you could do a
Code:
str_replace('{base_url}', base_url(), $database_field_with_links);
#6

[eluser]TexMax007[/eluser]
Those are some really good suggestions. I'll plan on trying the {base_url} replace thing, that should do what I want it to do. I'm about to call it for today, but I'll try it on by Tuesday and let you know if it works or not.

Thanks for the help, I really do appreciate it.

When I was researching php frameworks, everyone was raving about the community support, and now I see why.

Have a great weekend.
#7

[eluser]InsiteFX[/eluser]
If you want to use those kind of links all you to do is add this in your html head section.
Code:
&lt;base href="&lt;?php echo base_url();?&gt;" /&gt;
#8

[eluser]TexMax007[/eluser]
I ended up going with adding &lt;base href="&lt;?php echo base_url(); ?&gt; /&gt; to my head section.

Thanks for all of your help!

People from the future look below! Smile

Summary:

Needed links within a database to have my base_url prepended to them on processing.

Solution:

Add &lt;base href="&lt;?php echo base_url(); ?&gt;" /&gt; to your head section.




Theme © iAndrew 2016 - Forum software by © MyBB