public function links($view = 'datagrid.pagination') { if ($this->total_pages < 2) { return ''; } return blade($view, get_object_vars($this)); }
Deficient::boot("./"); ## burp, move it somewhere route_get('page/(\\d+)', array('as' => 'page', function ($page) { Zofe\Burp\BurpEvent::queue('dataset.page', array($page)); })); //define some general purpose events on query-string route_query('ord=(-?)(\\w+)', array('as' => 'orderby', function ($direction, $field) { $direction = $direction == '-' ? "DESC" : "ASC"; Zofe\Burp\BurpEvent::queue('dataset.sort', array($direction, $field)); }))->remove('page'); ## test routes route_get('^/{page?}$', array('as' => 'datagrid', function () { $grid = DataGrid::source(new User()); $grid->add('id', 'ID', true)->style('width:100px'); $grid->add('name', 'Name', true); $grid->paginate(5); echo blade('datagrid.tests.datagrid', compact('grid')); die; })); route_get('^/dataset/{page?}$', array('as' => 'dataset', function () { $ds = DataSet::source(new User()); $ds->paginate(5); $ds->build(); echo blade('datagrid.tests.dataset', compact('ds')); die; })); route_missing(function () { echo blade('datagrid.tests.error', array(), 404); die; }); route_dispatch();
<?php require_once __DIR__ . '/vendor/autoload.php'; use Zofe\Deficient\Deficient; Deficient::boot("./"); route_get('^/$', array('as' => 'home', function () { echo blade('deficient.hello'); })); route_get('^/test/(\\w+)$', array('as' => 'test', function ($slug) { echo blade('deficient.hello', array('title' => $slug, 'content' => 'Hello ' . $slug)); })); route_get('^/users$', function () { dd(User::all()->toJson()); }); route_missing(function () { echo blade('deficient.error', array(), 404); die; }); route_dispatch();
<?php require_once __DIR__ . '/vendor/autoload.php'; use Zofe\Deficient\Deficient; use Zofe\DataForm\DataForm; Deficient::boot("./"); ## burp, move it somewhere route_any('store', array('as' => 'save', function () { Zofe\Burp\BurpEvent::queue('dataform.save'); })); route_any('^/{save?}$', array('as' => 'home', function () { $form = DataForm::create(User::find(1)); $form->text('name', 'Name')->rule('required'); $form->textarea('lastname', 'Lastname'); $form->checkbox('enabled', 'Enabled'); $form->submit('Save'); $form->saved(function () use($form) { $form->message("ok record saved"); $form->linkRoute("home", "Back to the Form"); }); echo blade('dataform.tests.form', compact('form')); })); route_missing(function () { echo blade('dataform.tests.error', array(), 404); die; }); route_dispatch();
protected function getCellValue($column, $tablerow, $sanitize = true) { //blade if (strpos($column->name, '{{') !== false) { if (is_object($tablerow) && method_exists($tablerow, "getAttributes")) { $fields = $tablerow->getAttributes(); $relations = $tablerow->getRelations(); $array = array_merge($fields, $relations); $array['row'] = $tablerow; } else { $array = (array) $tablerow; } $value = $this->parser->compileString($column->name, $array); //eager loading smart syntax relation.field } elseif (preg_match('#^[a-z0-9_-]+(?:\\.[a-z0-9_-]+)+$#i', $column->name, $matches) && is_object($tablerow)) { //switch to blade and god bless eloquent $expression = '{{$' . trim(str_replace('.', '->', $column->name)) . '}}'; $fields = $tablerow->getAttributes(); $relations = $tablerow->getRelations(); $array = array_merge($fields, $relations); $value = $this->parser->compileString($expression, $array); //fieldname in a collection } elseif (is_object($tablerow)) { $value = @$tablerow->{$column->name}; if ($sanitize) { $value = $this->sanitize($value); } //fieldname in an array } elseif (is_array($tablerow) && isset($tablerow[$column->name])) { $value = $tablerow[$column->name]; //none found, cell will have the column name } else { $value = $column->name; } //decorators, should be moved in another method if ($column->link) { if (is_object($tablerow) && method_exists($tablerow, "getAttributes")) { $array = $tablerow->getAttributes(); $array['row'] = $tablerow; } else { $array = (array) $tablerow; } $value = '<a href="' . $this->parser->compileString($column->link, $array) . '">' . $value . '</a>'; } if (count($column->actions) > 0) { $key = $column->key != '' ? $column->key : $this->key; $keyvalue = @$tablerow->{$key}; $value = blade('datagrid.actions', array('uri' => $column->uri, 'id' => $keyvalue, 'actions' => $column->actions)); } return $value; }