2

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?

Lajos Veres
  • 13,595
  • 7
  • 43
  • 56
ClarkeyBoy
  • 4,934
  • 12
  • 49
  • 64
  • I think the majority of my questions havent actually had a correct answer as such, therefore 40% is probably about right.. – ClarkeyBoy Aug 02 '10 at 15:34
  • Then post your own solution and choose it as the right answer. – John Conde Aug 02 '10 at 16:12
  • Sometimes I dont find an answer, move on and forget about it (or trying to find the solution causes other major problems which I then get hooked on trying to solve, and forget about it..). I cant help it if I sometimes get sidetracked. – ClarkeyBoy Aug 02 '10 at 16:32

4 Answers4

5

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.

Wrikken
  • 69,272
  • 8
  • 97
  • 136
3

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...

ircmaxell
  • 163,128
  • 34
  • 264
  • 314
2

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.

chiborg
  • 26,978
  • 14
  • 97
  • 115
  • I have looked into Prado recently but I think, at the moment, with an exam to revise for and 5 projects to work on after the exam (not to mention job / house hunting) I probably have a bit too much on at the moment to learn a new framework any time soon. I will make sure to do so in the future though. Thanks for the suggestion anyway. Regards, Richard – ClarkeyBoy Aug 04 '10 at 23:48
0

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

Mark Baker
  • 209,507
  • 32
  • 346
  • 385