/** * Associates code with the page. This code will be executed within * a brand new page when called by URL. * * @param callable $method_or_arg Optional argument * @param callable $method function($page){ .. } * * @return $this */ public function set($method_or_arg, $method = null) { $method = is_callable($method_or_arg) ? $method_or_arg : $method; $arg = is_callable($method_or_arg) ? null : $method_or_arg; $self = $this; if ($this->isActive($arg)) { $this->app->addHook('post-init', function () use($method, $self) { $page = $self->getPage(); $page->id = $_GET[$self->name . '_id']; $self->app->stickyGET($self->name . '_id'); try { call_user_func($method, $page, $self); } catch (Exception $e) { // post-init cannot catch StopInit if ($e instanceof Exception_StopInit) { return; } throw $e; // exception occured possibly due to a nested page. We // are already executing from post-init, so // it's fine to ignore it. } //Imants: most likely forgetting is not needed, because we stop execution anyway //$self->app->stickyForget($self->name.'_id'); //$self->app->stickyForget($self->name); }); throw $this->exception('', 'StopInit'); } return $this; }
public function init() { $this->app->page_object = $this; $this->template->trySet('_page', $this->short_name); if (method_exists($this, get_class($this))) { throw $this->exception('Your sub-page name matches your page class name. ' . 'PHP will assume that your method is constructor.')->addMoreInfo('method and class', get_class($this)); } if ($this->app instanceof App_Frontend && @$this->app->layout && $this->app->layout->template->hasTag('page_title')) { $this->app->addHook('afterInit', array($this, 'addBreadCrumb')); } if ($this->app instanceof App_Frontend && $this->app->template->hasTag('page_metas')) { $this->app->addHook('afterInit', array($this, 'addMetas')); } if ($this->app instanceof App_Frontend && $this->app->template->hasTag('page_title')) { $this->app->addHook('afterInit', array($this, 'addTitle')); } parent::init(); }