getPrimaryKey() public méthode

Get primary key of datagrid data source
public getPrimaryKey ( ) : string
Résultat string
Exemple #1
0
 /**
  * @param string     $key
  * @param string     $name
  * @param string     $href
  * @param array|null $params
  * @return static
  */
 public function addAction($key, $name, $href = NULL, array $params = NULL)
 {
     if (isset($this->actions[$key])) {
         throw new DataGridException("There is already action at key [{$key}] defined for MultiAction.");
     }
     $href = $href ?: $key;
     if (NULL === $params) {
         $params = [$this->grid->getPrimaryKey()];
     }
     $action = new Action($this->grid, $href, $name, $params);
     $action->setClass('');
     $this->actions[$key] = $action;
     return $this;
 }
Exemple #2
0
 /**
  * Render item detail button
  * @param  mixed $item
  * @return Html
  */
 public function renderButton($item)
 {
     if (is_object($item)) {
         $id_value = $item->{$this->grid->getPrimaryKey()};
     } else {
         $id_value = $item[$this->grid->getPrimaryKey()];
     }
     $a = Html::el('a')->href($this->grid->link('getItemDetail!', ['id' => $id_value]))->data('toggle-detail', $id_value)->data('toggle-detail-grid', $this->grid->getName());
     if ($this->icon) {
         $a->add(Html::el('span')->class(DataGrid::$icon_prefix . $this->icon));
         if (strlen($this->text)) {
             $a->add(' ');
         }
     }
     $a->add($this->text);
     if ($this->title) {
         $a->title($this->title);
     }
     if ($this->class) {
         $a->class($this->class);
     }
     return $a;
 }