Welcome Guest, Not a member yet? Register   Sign In
base_url() not being parsed (from HTML stored in SQL database)
#1

[eluser]cjones26[/eluser]
*EDIT*

I've found the real problem to be the fact that I'm echo'ing HTML containing PHP in my view like so:

<?php echo $content; ?>

Where content contains more PHP code. Is there any way to recursively parse echo'ed PHP?

*EDIT*

Hello everyone,

I'm rather new to CodeIgniter & decided to try & convert my girlfriend's website into a CodeIgniter application.

The idea idea is to have a MySQL database containing a "PageContent" table (w/3 rows: id, name, data). Before & after inserting data into the table, I'm using PHP's add/removeslashes functions to ensure the quotations won't cause an issue.

I've got a single controller, named Page, who's index takes a single parameter--page name. From here, it passes this name to the model & pulls the appropriate page from the DB.

The problem is that the code pulled from the DB (which contains PHP for base_url()) is not getting parsed, and I end up with something like this in the page source:

Code:
<img src="&lt;?=base_url()?&gt;images/head_shot2.jpg" class="image1" alt="Head Shot Photo" />

Any ideas would be greatly appreciated.

-cjones
#2

[eluser]Nick_MyShuitings[/eluser]
I'm interested to how that'll scale for you, it doesn't seem like the best way to work things out.... which is just me subtly asking you why you chose that method...

regardless I think this is what you're looking for:

http://php.net/manual/en/function.eval.php
#3

[eluser]cjones26[/eluser]
[quote author="Nick_MyShuitings" date="1283420763"]I'm interested to how that'll scale for you, it doesn't seem like the best way to work things out.... which is just me subtly asking you why you chose that method...

regardless I think this is what you're looking for:

http://php.net/manual/en/function.eval.php[/quote]

Thanks for the response Nick, I managed to find eval on Google but also determined that it's very unsafe. I thought this method would be a good idea but now I'm understanding it's not. Would you have any suggestions or references on better methodologies?

Maybe I could just store the text in the SQL database (thought this may not work as every page has a slightly different design in the content section)?

Thanks again!
#4

[eluser]Nick_MyShuitings[/eluser]
Well, in this specific example, you could also print in the plain text for the base_url. ie, interpret your php before you stick it into the database.

I personally try to break my controllers out by logical function. There's no need to do one per page, but you can definitely have a quiz controller, a blog controller etc.

Another good option is creative view template usage. For example you could store the following in the db: name, desc, body, image1, image2, image3, view_ID. And you can display the information differently depending on which view you push it to.

Try and avoid the extremes of having a controller for each page, but also avoid the extreme of storing everything in the database and routing it all through one controller... if you're doing that then you are storing your application logic in the database instead of in the controllers like its supposed to... and don't even mention when you decide to redesign all of your pages.

(if you want your database to own your soul then go try drupal... shudder, then you will come back to codeigniter and happily write a new controller for each type of content you want to control and display).
#5

[eluser]cjones26[/eluser]
Haha, excellent response, I'll try to stick to the basics of DB logic in the model & app logic in the controller.




Theme © iAndrew 2016 - Forum software by © MyBB