Reputation: 1794
in asp.net there are controls like grideview, menus, .....
how to develop a web control in php like an editor [html, jscript, ajax calls to server] it is used repeatedly and the improvement of control will be better if we can separate it?
Upvotes: 1
Views: 2915
Reputation: 28164
First of, be aware that in PHP "control" and worse, "controller" means completely differently.
I've not used ASP, but I've used Delphi extensively, as well as Delphi for PHP, which does the same thing you are asking about (yes, in PHP).
Basically, you need some sort of framework to build this stuff on, as Johann said, you might want to use MVC, but you don't really have to.
Example of such a system (without MVC):
class TControl {
public $width=0;
public $height=0;
public $name='ControlN';
public function render(){
echo '<div style="width:'.(int)$this->width.'px; height:'.(int)$this->height.'px;"/>';
}
}
class TLabel {
public $caption='Label';
public function render(){
echo '<div style="width:'.(int)$this->width.'px; height:'.(int)$this->height.'px;">'.htmlspecialchars($this->caption,ENT_QUOTES).'</div>';
}
}
$label=new TLabel();
$label->width=200;
$label->height=24;
$label->caption='My label!';
$label->render();
Upvotes: 3
Reputation: 2667
ASP.net tries to mimic Windows Forms, this allows Windows Forms users to quickly get a website up and running. And as it mimics Windows Forms they created several preloaded user controls that you can insert into a web page. All these do is produce the styles, JavaScript and the HTML necessary to show the control on the client browser with your configured options. You could try to produce a similar effect in PHP , with .php that you include. For example creating a button.php and then including it where you want the button to be displayed.
But for simplicity I find that the MVC approach to development with PHP and a Framework is much more cleaner.
Upvotes: 1
Reputation: 1273
In PHP you write all 'controllers' in plain HTML.
If you want 'controllers' that you use more often, then make functions for them, f.ex;
function list($array)
{
$output = '';
foreach($array as $item) $output .= "<li>$item</li>";
return "<ul>$output</ul>";
}
Now you got an 'list controller'.
Upvotes: 1