使用PHP代码存储页面的方法

我正在创建一个网页,我遇到了一个问题,我找不到答案。 我正在使用Laravel框架,我需要以某种方式存储页面。 我通常会使用MySQL或SQLite或其他类似的数据库引擎,但我编写的一些页面包含PHP代码。</ p>

具体来说,页面/应用程序使用file_get_contents从某处下载某些内容, 转换编码魔术并显示下载的内容。 Page /只是普通的Html。
我想过使用eval(),但这对我来说似乎是一种极端的过度杀伤和不安全感。 另外,我想通过在控制器中使用/ app的逻辑以及在某些DB中使用页面文本来以某种方式利用MVC。 所以我需要找到一些允许我这样做的模型。</ p>

我正在使用“每页功能”方法。
i.e。</ p>

 类MainController扩展BaseController {
公共函数getIndex(){//某些代码}
公共函数getApp(){//某些代码}
公共函数getDocs(){/ /某些代码}
}
</ code> </ pre>

等... </ p>

有关如何处理它的任何想法?</ p>

编辑:

一点背景知识。 我不是新手,只是我不知道如何处理这个项目。 我有使用Laravel编写博客等项目的经验。 </ p>

我正在创建的页面是“组合类型”; 主要是静态的,但是2页包含如上所述的脚本。
另外我已经有了工作版本,但我从头开始重写它。 原始版本使用Slim框架和页面存储为php文件,然后包含到基于url的模板。</ p>

  include“pages / $ url_part.inc.php”; 
< / code> </ pre>
</ div>

展开原文

原文

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";

duanchu7271
duanchu7271 谢谢你的建议,我会那样做!:)再一次谢谢你。
5 年多之前 回复
duanbei2914
duanbei2914 共约15页,2页代码
5 年多之前 回复
dongman5539
dongman5539 这个问题会影响多少页?如果只是一只手,我会用单独的路线/控制器重写它...
5 年多之前 回复
douyao7390
douyao7390 我可以重做整个事情,但我的想法已经不多了。是的,我知道这现在与MVC不对应。
5 年多之前 回复
dou5454954610
dou5454954610 这听起来不太好。有没有办法以更面向对象的方式重新设计网站?至少,这将是我想到的第一种方法。除了你已经指出的那个之外,我认为没有任何可能做你想做的事。此外,这个概念与mvc不对应......
5 年多之前 回复

1个回答



因为这个 SO答案指出,除了 eval </ code>之外,没有办法执行驻留在数据库中的php代码。</ p >

我的建议是尝试学习laravel和 MVC </ strong>,然后重新设计应用程序。 我不能建议学习laravel的资源是 Laracasts 。 Laracasts还提供了一个非常完善的系列,名为 Laravel from Scratch 。 但是很有可能你已经知道了。</ p>

再次解决你的问题:我认为值得考虑重新设计整个应用程序。 由于laravel的工作流程非常快,所以最好早点完成,因为你的设计将来会导致更多的问题,因为它根本不适合laravel。 此外,这将开辟许多不错的可能性,因为你可以使用laravel的全部功能。</ p>

数据库是 models </ code>背后的东西,< MVC </ strong>中强> M </ strong>。 只有实际数据应该存储在那里,没有逻辑</ strong>( C </ strong> - 控制器</ strong>)或演示文稿( V </ strong> - 查看</ strong>)。</ p>

如果它只是一个普通的网站(如博客或某事),请考虑不要自己开发。 市场上有很多免费的内容管理系统(如Wordpress,一个非常受欢迎的系统),它也提供了很多扩展和定制的可能性。 </ p>

鉴于您提供的信息很少,这是我迄今为止唯一的建议。 我希望这有助于一个小小的,如果这些东西对你的知识水平是基本的,那就很抱歉,但很多时候很难说OP在多数情况下是多么熟练。</ p>
</ div>

展开原文

原文

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.

dpd3447
dpd3447 编辑了我的问题
5 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问