0

I'm currently creating a webpage and I have a problem, which I couldn't find answer for. I'm using Laravel framework and I need to store pages somehow. I would normally use MySQL or SQLite or some other DB engine like that, but some of the pages I write contain PHP code.

Specifically, page /app downloads something from somewhere using file_get_contents, does magic with converting encoding and displays the downloaded content. Page / is just plain Html. I thought about using eval() but it seems like an extreme overkill and insecurity to me. Also I would like to leverage the MVC somehow in this by having the logic of /app in controller and the text of the page in some DB. So I need to find some type of model which would allow me to this.

I'm using the "function-per-page" approach. i.e.

Class MainController extends BaseController {
    public function getIndex() { // some code }
    public function getApp() { // some code }
    public function getDocs() { // some code }
}

etc...

Any ideas on how to deal with it?

EDIT:
A little bit of background. I'm not a newbie, it is just that I don't know how to deal with this project. I have experience in writing projects like blogs using Laravel.

The page I'm creating is "portfolio-type"; mostly static, but 2 pages contains scripts as stated above. Also I already have working version, but I'm rewriting it from scratch. Original version used Slim framework and pages were stored as php files, then included to template based on url.

include "pages/$url_part.inc.php";
FHR
  • 77
  • 6
  • 1
    This doesn't sound very well designed. Is there any way to redesign the site in a more object oriented way? At least, this would be the first approach which comes to my mind. I don't think there are any possibility to do what you want besides the one you already pointed out. Also, this concept does not correspond to mvc... – nozzleman Jan 22 '15 at 21:02
  • I could redo do whole thing, but I am running out of ideas. And yes, I know this doesn't correspond to MVC right now. – FHR Jan 22 '15 at 22:19
  • 1
    how many pages are affected by this issue? if its just a hand full, i would rewrite it with seperate routes/controllers... – nozzleman Jan 23 '15 at 17:54
  • About 15 pages in total, 2 pages with code – FHR Jan 23 '15 at 19:00
  • @nozzleman Thank you for your suggestion, i will do it that way! :) Once more thank you. – FHR Jan 23 '15 at 19:06

1 Answers1

0

As this SO Answer states, there is no way besides eval to execute php code that resides in a database.

My suggestion would be to try and learn a bit about laravel and MVC and to redesign the application afterwards. A resource I can not recommend enough for learning laravel is Laracasts. Laracasts also provides a very well done series called Laravel from Scratch. But chances are good you already know that.

To address your issue once more: I think it is worth thinking about a redesign of the whole app. Since the workflow with laravel is super fast, this is better done sooner than later, because your design will lead to more problems in the future, because it simply does't fit well with laravel. Also, this will open up a lot of nice possibilities, because you can use the full power of laravel.

The Database is what lies behind models, the M in MVC. Only actual Data should be stored there, no Logic (C - Controller) or Presentation (V - View).

If it is just a normal website (like a Blog or sth.), think about not developing it all by yourself. There are great free Content-Management-Systems on the Market (like Wordpress, to name a very popular one), which also offer a lot of possibilities for extension and customization.

Given the little information you gave, this is the only advice I can give so far. I hope this helps a litte, and sorry if this stuff is to basic for your level of knowledge, but it is hard to tell how proficient the OP is in many cases.

Community
  • 1
  • 1
nozzleman
  • 9,529
  • 4
  • 37
  • 58