id = self::$idx ++; $this->setUp(); } function setUp() { } public function getName() { return self::$prefix . intval($this->id); } /** * Генерация кода инициализации компонента на стороне клиента */ public function getCodeBefore() { $result = // "alert('".$this->getName()."');" . "var " . $this->getName() . " = new " . get_class($this) . "(" . json::encode($this->data) . ");"; return $result; } public function setData($name, $value) { $this->data[$name] = $value; } public function getCodeAfter() { return $this->getName() . ".appendTo(document.getElementById('" . $this->getName() . "'));\n"; } public function postMake() { } /** * Генерация компонента */ function make(Controller $parent) { $this->view = $parent->getView($this->template); // Controller $this->view->index = $this->getName(); foreach ($this->data as $name => $value) { $this->view->set($name, $value); } $this->view->addScriptRaw($this->getCodeBefore(), true); $this->postMake(); $this->view->addScriptRaw($this->getCodeAfter(), true); } } ?>