Welcome Guest, Not a member yet? Register   Sign In
Getting codeigniter to accept asset references
#1

[eluser]Unknown[/eluser]
I'm aware that the 'best practice' is to move assets to the root and include base_url in front of every asset reference in your documents. This is fine..except when you are transferring existing documents from another website or including pre-formatted boilerplates and bootstraps who have their own ideas of how assets should referenced in the DOM (here's a hint: their ideas are w3 standard).

So lets say I dont want to regexp into my documents and concatenate base_url to every single reference. How can I tell codeigniter 'hey, please act normal when it comes to assets in documents, kay thanks'.


Smile
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

I don't think the problem is with CodeIgniter. All CodeIgniter does is dish up the file(s) you instruct it to. Once the browser receives the HTML, it simply follows any URLs to get the corresponding assets. Other than dynamically replacing the URLs on-the-fly, I think just doing a search and replace is your only option.
#3

[eluser]Unknown[/eluser]
Hi! Thanks for the welcome.

Grepping or regexing through your docs does seem to be the only viable solution at the moment.

Since someone else who is looking for advise might find this, here's what I did with some quick minute regex to replace my relative asset references in my doc markup files.

Code:
hhref="(?!http)(?!<\\\\?)(?!//)(.*?)"

(?!<\?) there should only be a single backslash there. Dunno why the forum keeps escaping it in the code example above.

Replace href with src accordingly.

Search and replace and use the last variable as your replace reference concatenated to &lt;?=base_url()?&gt; or whatever path you choose.




Theme © iAndrew 2016 - Forum software by © MyBB