Welcome Guest, Not a member yet? Register   Sign In
URL-s in database
#1

[eluser]KSiimson[/eluser]
Ok, maybe a silly question, but...

I store the articles of my web site in a database. Each article may contain URL-s to different pages on same web site. If I would have to change the URL of the web site, then the links would stop working. How do I avoid that from happening? Obviously I cannot store any PHP functions such as site_url(); inside the database, but what can I use? I can think of something similar to BBCode, but I have no clue how to implement that.
#2

[eluser]davidbehler[/eluser]
You could save the controller/function/parameter part instead of the whole url and then later on simply do
Code:
echo site_url($part_from_database);
#3

[eluser]slowgary[/eluser]
Why not just omit the domain portion of the URL in your links?
Code:
<a href='/controller/function/parameter'>click me if you dare</a>
#4

[eluser]KSiimson[/eluser]
[quote author="slowgary" date="1249207214"]Why not just omit the domain portion of the URL in your links?
Code:
<a href='/controller/function/parameter'>click me if you dare</a>
[/quote]

In most cases this would suffice. However, I don't keep the site on a top level address while it is still at production level. So instead of having the site at http://mysite.com/, it is at http://mysite.com/production. HTML is too dumb to figure out that this is my site root.

Just to let you know, the first answer did not answer my questions - although I really appreciate the effort. There will be a long text with some URL-s inside, URL-s are not contained in database separately.
#5

[eluser]jedd[/eluser]
[quote author="KSiimson" date="1249212642"] There will be a long text with some URL-s inside, URL-s are not contained in database separately.[/quote]

And there's your actual problem. Until you fix your design, you're going to have the problem of having to regexp through all text looking for things that might be a URL and then modifying them on the fly.

My guess is that for any URL-ish thing that doesn't include protocol or hostname components, you're going to have a lot of false positives - anytime anyone uses a slash, for example.
#6

[eluser]KSiimson[/eluser]
I suppose it's not really bad option at all, regular expressions are really fast and the texts aren't too long. With a special syntax for the local URL-s, there won't be any false positives either. I am still in the design stage, and I won't have to convert a bunch of existing URL-s, so it is not any trouble.

But I see you are suggesting there actually exists a better alternative?
#7

[eluser]jedd[/eluser]
Well, it depends how sophisticated you want to be, or your users are. Are you ever likely to have non-local site URL's stored in this system? The way that the CI forums (and most bbtext style things) do it is pretty sensible, to me - some very basic ML constructs. But then, we CI forum users are fairly sophisticated - or at the very least, we're not irrationally frightened of, or irretrievably confused by, square brackets.

I see only a couple of ways of doing this -- a ML construct (eg. CI's [ url= ... ]) and have everything in-line to your messages, but still algorithmically extractable and consequently modifiable en masse. The two variations of that approach are to provide an entire, valid, URL, or to just provide enough to append onto a base_url().

Or a db table of URL's and do footnote style references (still need some basic markup to denote these, of course). The latter makes it slightly easier to make changes across the board. I don't know which makes it easier to differentiate internal from external links - but this may not be important to you.

There may be better ways of handling these, of course. My approach to URL handling at the moment is to have a UUID against each unique URL, but I need to be able to track off-site URL's, and be able to n:n map them to annotations, people, sites, and a few other db entities I have. I have not yet resolved about whether I want the pain, or need the benefits, of differentiating between local and non-local URL's. As above, it should be fairly easy to batch through a data source looking for local URL's and making whatever regexp changes you need.




Theme © iAndrew 2016 - Forum software by © MyBB