将元素添加到其他元素

发布于 2024-09-12 03:41:06 字数 915 浏览 9 评论 0原文

过去几年我一直在使用 .net,我喜欢这种可以在页面的任何位置从任何位置添加控件的方式。例如,您可以说 Head.Controls.add(new LiteralControl("")) 即使已经有一具尸体了。

在php中可以做这样的事情吗?我的网站的设置是为了让我们拥有代理商、客户和艺术家(这是为一家卡片制造公司提供的,该公司希望客户应用程序可以在贸易展览会上离线使用)。添加代理表单可能与添加客户表单具有不同的样式。因此,我希望将每种类型放在不同的文件夹中(例如代理、客户和艺术家),每个类型都有自己的样式表。将有一个表单页面,它采用 GET 类型参数(艺术家、客户等)、模式(创建、编辑)和可选 ID 参数(处于编辑模式时)。我希望能够一次性调用 $agentForm->generateForm()$agentForm->generateStyleTag(),而不是我当前正在做的事情即在正文中调用 $agentForm->generateForm() ,在头部调用 $agentForm->generateStyleTag (甚至还没有生成开始正文标记) )。

一个好方法是我有一个 Head 标签和 Body 标签。在另一个名为 $agentForm->generateHTML() 的函数中,我想说 Body->addChild("bla")Head->addChild( “bla”)。这使得开发新页面变得更加容易,因为它确保样式存在并且对于用户所在站点的部分来说是正确的。

是否可以实现这一点,或者这是 php 和 .net 之间的主要区别之一?

I have been using .net for the past couple of years, and I like the way you can add controls at any point in the page from anywhere. For example, you can say Head.Controls.add(new LiteralControl("<link rel='stylesheet' type='text/css' href='styles.css' />")) even if there is already a body.

Is it possible to do this kind of thing in php? My site is set up so that we have agents, customers and artists (this is for a card manufacturing company who wants a customer application for use offline at tradeshows). The add agent form may have different styles to the add customer form. I want to therefore have each type in a different folder (for example agents, customers and artists) each with their own stylesheet. There will be one form page which takes GET parameters of type (artist, customer etc), mode (create, edit) and an optional parameter of ID (when in edit mode). I would like to be able to call $agentForm->generateForm() and $agentForm->generateStyleTag() in one go, rather than what I am currently doing which is to call $agentForm->generateForm() in the body and $agentForm->generateStyleTag when in the head (without even the start body tag being generated yet).

A good way to put this is that I have a Head tag and a Body tag. In another function called $agentForm->generateHTML() I want to say Body->addChild("bla") and Head->addChild("bla"). This makes developing a new page a lot easier since it ensures the styles are there and are correct for the section of the site the user is in.

Is it possible to achieve this, or is this one of the major differences between php and .net?

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

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

发布评论

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

评论(4

度的依靠╰つ 2024-09-19 03:41:07

PHP 本质上只是为了将字符串扔到 STDOUT 中而设计的,除非经过缓冲。为了实现这一点,您必须使用支持此功能的模板系统,或者推出您自己的模板系统。没有“内置”模板系统,除非您将整个内容加载到 DOMDocument 或其他内容中,并进行主要的原始 DOM 操作,这会慢很多,除非您计划进行大量其他 DOM 修改,否则我不会推荐这样做。谷歌搜索 PHP 模板系统并检查哪一个可以满足您的需求。

PHP is in essence designed just to throw strings into STDOUT, unless buffered. To make this work, you'd have to use a templating system that supports this, or roll your own. There is no 'built-in' templating system unless you count loading the whole thing in DOMDocumentor something, and do major raw DOM manipulations, which would be quite a lot slower, and which I wouldn't recommend unless you plan to do a whole lot of other DOM modifications. Google around for PHP templating systems and check which one supports your needs.

南城追梦 2024-09-19 03:41:07

你需要意识到一些事情。 .NET 是一个框架,而不是一种编程语言。该问题与Can you do this in C#相同。意识到您正在将苹果与橙子进行比较。

PHP 语言是图灵完备的,所以是的,你可以做到。这并不意味着执行此操作的代码已经编写(可能是)或者它会很容易(谁知道)。这仅意味着这是可能的。

话虽如此,您需要找到一个框架来完成您想做的事情。没有语言会附带这种操作(因为它对整个语言的限制太大)。所以你的任务不再是“PHP可以做到这一点”,而是“我需要找到一个框架来做到这一点”。尝试研究框架,我敢打赌你会很容易找到答案......

You need to realize something. .NET is a framework, not a programming language. The question is identical to Can you do this in C#. Realize that you're comparing Apples to Oranges.

The PHP language is Turing complete, so yes you can do it. That doesn't mean the code to do it is written yet (it may be) or that it will be easy (who knows). It only means it's possible.

With that said, you need to find a framework to do what you want. No language will come with that kind of operation (since it is far too limiting to the language as a whole). So your task is no longer "Can PHP do this", but "I need to find a framework to do this". Try looking into frameworks, and I'll bet you'll find your answer quite easily...

ヤ经典坏疍 2024-09-19 03:41:07

查看 PRADO 框架和 Yii 框架。他们有一个分层的、基于组件的理念,允许嵌套和组合,本质上是用更小的、可插入的组件构建整个网站。

Have a look at the PRADO framework and the Yii framework. They have a hierarchical, component-based philosphy that allows nesting and composition, essentialling building a whole site from smaller, pluggable components.

生生漫 2024-09-19 03:41:07

正如已经指出的,PHP 是一种语言,而.Net 是一种框架。两者是非常不同的事情。

如果您想使用 PHP 作为 .Net 的脚本语言,总有 Phalanger< /a>

As has already been pointed out, PHP is a language, while .Net is a framework. The two are very different things.

If you want to use PHP as a scripting language for .Net, there's always Phalanger

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