PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
that is the first I've ever heard of those functions. I could see how they would be useful for XML type documents, but how/why else would you use them? Given that PHP is server side, I have a hard time understanding why you'd need access to the DOM to serve up pages. I could potentially see some benefit with things like file_get_contents() to help parse out the string, and make changes to served pages, but beyond that, how can you have interactivity with the DOM with php?
Burrito wrote:that is the first I've ever heard of those functions. I could see how they would be useful for XML type documents, but how/why else would you use them? Given that PHP is server side, I have a hard time understanding why you'd need access to the DOM to serve up pages. I could potentially see some benefit with things like file_get_contents() to help parse out the string, and make changes to served pages, but beyond that, how can you have interactivity with the DOM with php?
Ohh... the possibilities are endless if you throw DOM into a template/MVC system
d11wtq wrote:Ohh... the possibilities are endless if you throw DOM into a template/MVC system
sorry for my ignorance, but I'd love for you to help an old man out and give me an example
I don't have one. I wasn't implying I've done it, I was saying it would be nice. I have thought about it in the past because my template stuff already does things like this. This is oibviously a completely stupid example but it's much like cut and paste... but with parts of a page.
<?php
class View
{
// ... snip ...
public fuction blahBlahBlahAndErmmBlah()
{
$node = $this->template()->copy("my_tag");
$block = $this->template()->cut("some_block"); //Can also be used to delete
$this->template()->replace("foo", $node);
$this->template()->append($block);
}
}
again, excuse the ignorance, but how would doing something like that be advantageous to just writing out the html? (I mean using the library of functions to create / remove / etc elements in the DOM, not using MVC or any other design pattern.) I'm having a hard time wrapping my head around the advantages to using these functions. The object model makes perfect sense to me on pages that are loaded (to be able to manipulate them after they've been pulled down), but I just can't seem to grasp the benefit of using them server side.
a scenario like this perhaps???
A CMS system that uses a templating engine. A user wants to create a form and needs to add elements to the form. They select the elements to add, submit the page, and based on the selections made, the form gets built by these functions? I can sort of see some potential there, but still seems like using a sledge hammer to push in a thumbtack.
It just gives me more control over the features on the template (delete and edit buttons for admin users maybe?) from within the view rather than directly placing such logic in the template. I use this to set CSS/JavaScript into the <head> of a larger page at runtime.
Your example is a reasonably good one anyway. The controller picks up what the user wants to do and the view then makes those changes on the template. Using other means you'd need more PHP code directly in the template itself, which is fine if it's minimal logic but for scarier, more complex logic I just like this approach. Maybe it's hackish, I've never actually had anybody else review what I'm doing