构建 PHP WYSIWYG 编辑器
我正在构建一个 Web 应用程序,用户可以在其中添加页面、编辑布局、拖放元素、调整元素大小、格式化文本、编辑元素属性等。
在页面中,用户可以包含(检索)动态数据,例如数据库中的数据、php 代码生成的数据等。
我最近玩过 cakephp 和 jquery 并尝试构建这个应用程序。但我偶然发现了如何正确显示 php 代码。我试图研究 cakephp 核心代码并找到有关输出缓冲的信息,并尝试利用输出缓冲来解析 php 代码并使用正则表达式来显示它,但如果我自己编写解析器,则更有可能重新发明轮子
我要问的是:
好的,更简单和具体,我只是想问,如何保存和加载用户创建的页面,特别是如果页面包含 php 代码。我只是想知道除了编写自己的解析器或者可能是解析 php 代码的库之外还有其他方法吗?
好了,现在就这些了,有人知道如何实现吗?或者也许有任何页面/网站可以提供一些有用的参考?也许是我可以参考的示例代码
谢谢
I am building a web application in which the user may add a page, edit the layout, drag drop element, resize element, format the text, edit the element attribute etc.
In the page the user may include (retrieve) dynamic data, like maybe data from database, data generated by php code, etc.
I have played around with cakephp and jquery lately and tried to build this app. But I stumbled upon on how to appropriately display the php code. I tried to look into the cakephp core code and find about output buffering and tried to utilize output buffering to parse the php code and use regex to display it but it is more likely to reinvent the wheel if I write the parser my self
What I am asking is:
Ok, to be more simple and specific I just want to ask, how to save and load the page that was created by the user especially if the page contains php code. I just want to know is there any other method than write my own parser or maybe a library to parse a php code?
Ok that's all for now, does anyone have any idea how to implement it? Or maybe any page / website that could be useful to take some reference from? Maybe a sample code from which I can take some reference
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你能在这里找到任何好的答案。
哇我不知道从哪里开始。我将从数字 3 开始。您需要小部件。那么这意味着您必须创建拥有模板或使它们“好吧,有点”可绘制的小部件类或对象。如果我是你,它会从 javascript 加载,而不是真正从 php 加载。每个小部件都以某种方式成为使用 javascript 加载到 div 中的单独应用程序。
第 2 点,你想要小部件。当您向页面添加小部件时,您必须保存一些信息,例如位置、标题、尺寸等。您甚至可以保存创建参数。例如,ListWidget 可以使用不同的 ItemProvider 启动。这样您就不必编写 1000 个小部件,而只需编写一个显示不同内容的小部件。也就是说,你有小部件、尺寸和位置。现在我们来到第 1 点。
第 1 点。一旦您获得了小部件、位置和尺寸,您就可以将用于创建与页面关联的数据的数据发送到服务器。这再次让我们领先2分2分。
保存页面后。您可以通过检索带有参数等的所有小部件来查看它。这给你留下了两个选择。
选项 1 更简单,因为选项 2 本身不会将 html 绑定到 javascript。另一方面,解决方案 2 更好,因为只有 1 个对服务器的请求。
哦,最后一件事,你应该给自己设定一些限制。这种事情可能会变得非常复杂,而且不幸的是,事情并没有那么好。例如,请参见 drupal。它可以做很多很酷的事情,但是一旦你安装了很多模块。 Drupal 将自己转变为某种吞噬记忆的怪物。而且几乎所有时候您并不真正需要那么多动态内容。固定布局几乎在 99% 的情况下都能很好地工作。
我也不得不这么说,但如果你尝试创建一个应用程序,为用户提供与养一只七足猫的科学家一样多的权力。我认为你会和一些非常不起眼的力量一起玩!
I'm not sure you'll find any good answer here about that.
Whoa I don't know where to start. I'll start by the number 3. You want widgets. Then that means you have to create widget class or objects that possesses a template or something that makes them drawable "well, kinda". If I were you it would be loaded from javascript and not really from php. Each widget would be in some way individual applications loaded in a div using javascript.
Point 2, You wanted widgets. When you add widgets to your page, you have to save some informations, like Position, Title, dimensions and so on. You may even save creation parameters. For exemple a ListWidget may be started with different ItemProvider. That way you don't have to write 1000 widgets but only one that shows different content. That said you have widgets, dimension and position. Now that lead us to point 1.
Point 1. Once you have your widgets, position and dimensions, you send the data you used to create them associated with the page to the server. That lead us two point 2 again.
Once you have saved a page. You can see it by retrieving all widgets with parameters and so on. That leaves you 2 options.
Option 1 is simpler since option 2 won't bind html to javascript by itself. Solution 2 on the other hand is better since there is only 1 request to the server.
Oh and a last thing, You should set yourself some limits. That kind of thing can get very complicated and unfortunately not that great. See drupal for example. It does lots of cool stuff but as soon as you install lots of module. Drupal transform itself in some sort of memory eating monster. And almost all the time you don't really need that much of dynamic content. Fixed layouts will do work nice almost 99% of the time.
I'm also forced to say that but if you try to create an application that give users as much power as a scientist that could raise a 7 legged cat. I think you're going to play with really obscure forces!