为什么所见即所得编辑器删除 PHP 代码?

发布于 2024-09-12 17:17:27 字数 66 浏览 3 评论 0原文

我使用输入格式为“PHP 代码”...输入 PHP 代码,看起来不错。下次我去编辑它时,它会全部删除。这非常令人沮丧。

I use input format as "PHP Code"...enter PHP code and it looks fine. Next time I go edit it, it removes it all. This is very frustrating.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离不开的别离 2024-09-19 17:17:27

WYSIWYG 编辑器可能会隐藏 PHP,因为它不是有效的 HTML,并且看起来像一个标签。检查源代码视图并查看代码是否仍然存在,但不可见。

就此而言,您应该使用纯文本编辑器编辑 PHP 文本字段,而不是所见即所得,因为它可能会更改“<” HTML 实体 (<) 等等。

The WYSIWYG editor may be hiding the PHP because it is not valid HTML, and looks like a tag. Check the Source view and see if the code is still there, but invisible.

For that matter, you should be editing a PHP text field with a plain text editor, not WYSIWYG, because it may be changing "<" to the HTML entity (& lt;) and so on.

呆橘 2024-09-19 17:17:27

格雷厄姆的回答解释了发生的情况,但您可以通过以下方法解决它。

但首先,警告:您确实应该避免在 Drupal Web 界面中编写 PHP,因为 PHP 存储在数据库中。它非常不安全(您必须非常小心站点权限)并且您没有版本控制的好处。考虑编写您自己的小型自定义模块/主题来完成 PHP 工作。

如果您使用WYSIWYG 模块安装了 WYSIWYG,则可以为 WYSIWYG 分配单独的配置每种输入格式。确保“PHP 代码”输入格式没有指定所见即所得,并且您不必担心默认情况下启用与禁用。也就是说,当您在文本字段中开始使用 PHP 进行编码时,您无法在 PHP 代码和启动 WYSIWYG 的输入格式之间来回切换。这会将 PHP 字符转义为 HTML 实体,正如 Graham 所说,并且会破坏你的代码(我有一个客户在一个块中对我的 PHP 代码执行此操作,这是不在站点 UI 本身中编写 PHP 的另一个原因)。

如果您使用更好的格式模块,您可以为您定义的每个用户角色分配默认输入格式在您的网站上。我这样做是为了完全避免这种情况。当我想在 Drupal 中进行一些 PHP 编码时,我使用的角色默认为不支持所见即所得的输入格式,所以我知道我永远不会意外地使用 PHP 打开节点/块并使其自动销毁由所见即所得编辑器编写。

Graham's answer explains what's happening, but here's how you might fix it.

But first, caveat: you should really avoid writing PHP in the Drupal web interface, where it gets stored in the database. It's very insecure (you have to be really careful with site permissions) and you don't have the benefit of version control. Consider writing your own small custom modules/themes to get PHP work done.

If you've installed your WYSIWYG using the WYSIWYG module, you can assign a separate configuration of your WYSIWYG for each Input Format. Make sure the "PHP code" input format has no WYSIWYG assigned, and you won't have to worry about Enabled vs Disabled by default. That said, when you start coding in PHP in a text field, you can't switch back and forth between PHP code and an input format that will start the WYSIWYG. This will escape PHP characters as HTML entities, as Graham said, and will destroy your code (I had a client do this to my PHP code in a block, which is another reason not to write PHP within the site UI itself).

If you use the Better Formats module you can assign a default Input Format to each user role you've defined on your site. This is what I do to completely avoid the situation. When I want to do some PHP coding inside Drupal, I use a role that defaults to an input format that doesn't enable my WYSIWYG, so I know I'll never accidentally open a node/block with PHP and have it auto-destroyed by a WYSIWYG editor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文