$this->_client_id = $client_id; } public function format($data, $type, $number = 0, $columns = null) { switch ($this->_field) { case 'actions': return '<a href="javascript:' . $this->_client_id . '.deleteItem(' . $data[0] . ');">Удалить</a>'; default: return parent::format($data, $type); } } } // Создаём DataSource $datasource = new grid_data_source(new grid_header_item_array(new grid_header_item('id', 'Id', type::STRING, true), new grid_header_item('title', 'Заголовок', type::STRING, true), new grid_header_item('actions', 'Действия', null, false, new my_grid_formatter('actions', $emanager->client_id())))); // Создаём новый грид и пейджер к нему $grid_pager = new ajax_grid_pager('my_grid_pager', mydata::get_total(), 5); $grid = new ajax_grid('my_grid', $datasource, $ajaxbuffer, $grid_pager); // выбираем текущую страницу отсортированных данных $mydata = mydata::get_page($grid_pager->get_pagesize(), $grid_pager->get_curpage(), $grid->get_sort_direction() != sorting::SORT_DIR_DESC); // добавляем данные в DataSource foreach ($mydata as $data) { $datasource->add_row(array($data[0], $data[1], $data)); } // чтобы было видно прогресс задержим рендеринг постбэка на секунду if ($ajaxbuffer->is_post_back()) { sleep(1); } // Выводим результат $templater = new templater(dirname(__FILE__) . '/templates/main.tpl.php'); die($templater->render(array('grid' => $grid, 'ajaxbuffer' => $ajaxbuffer, 'title' => 'Тестовая страница')));
<?php require_once 'app/templater.php'; # Make sure we have our requested film if (isset($_GET['film'])) { # Instantiate a new view $view = new templater('views/movies-view.php'); # Basic protection from script injection (you MUST do more if this will be sent to a database, see https://www.owasp.org/index.php/SQL_Injection) $output = htmlentities($_GET['film']); # Handle bad inputs if (strlen($output) < 1) { $output = 'Invalid input'; } # Set variable and render template $view->set('choice', $output); $view->render(); } else { # Redirect for errors header('Location:index.php'); }