You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

39 lines
1005 B

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: luocj
  5. * Date: 2017/5/31
  6. * Time: 14:07
  7. */
  8. namespace common\components;
  9. use yii\grid\ActionColumn;
  10. class zActionColumn extends ActionColumn
  11. {
  12. public $template = '{:view} {:update} {:delete}';
  13. /**
  14. * 重写了标签渲染方法。
  15. */
  16. protected function renderDataCellContent($model, $key, $index)
  17. {
  18. return preg_replace_callback('/\\{([^}]+)\\}/', function ($matches) use ($model, $key, $index) {
  19. list($name, $type) = explode(':', $matches[1] . ':'); // 得到按钮名和类型
  20. if (!isset($this->buttons[$type])) { // 如果类型不存在 默认为view
  21. $type = 'view';
  22. }
  23. if ('' == $name) { // 名称为空,就用类型为名称
  24. $name = $type;
  25. }
  26. $url = $this->createUrl($name, $model, $key, $index);
  27. return call_user_func($this->buttons[$type], $url, $model, $key);
  28. }, $this->template);
  29. }
  30. }