CodeIgniter(CI3)框架Grid_View库类

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Class Grid_View
 * Implements a simple encapsulation of CodeIgniter tables.
 * Can be used in views.
 */
class Grid_View
{
	private $app = NULL;
	function __construct()
	{
		$this->app = &get_instance();
	}

	/**
	 * Attributes that the model does not own will be retrieved from the CI application.
	 * Equivalent to inheriting CI_Model classes.
	 */
	public function __get($key)
	{
		return $this->app->$key;
	}

	/**
	 * Config template of table.
	 * @param array $tmpl
	 * @return $this
	 */
	public function template($tmpl = array())
	{
		$tmpl['table_open'] = element('table_open', $tmpl, '<div class="table-responsive"><table class="table table-hover" style="table-layout:fixed;word-break:break-all;">');
		$tmpl['heading_cell_start'] = element('heading_cell_start', $tmpl, '<th class="bg-success">');
		$tmpl['table_close'] = element('table_close', $tmpl, '</table></div>');
		$this->table->set_template($tmpl);
		return $this;
	}

	/**
	 * Config heading of table.
	 * @param array $heading
	 */
	public function heading($heading = array())
	{
		$this->table->set_heading($heading);
        return $this;
	}

	/**
	 * Config heading and template of table.
	 * @param $heading
	 * @param array $tmpl
	 * @return $this
	 */
	public function config($heading, $tmpl = array())
	{
		$this->template($tmpl)->heading($heading);
		return $this;
	}

	/**
	 * Use callback function to add table rows.
	 * @param array $rows
	 * @param $call_back //get $row and return $processed_row
	 * @return $this
	 */
	public function load($rows = array(), $call_back)
	{
		foreach ($rows as $row)
		{
			$this->table->add_row(call_user_func($call_back, $row));
		}
		return $this;
	}
	public function generate()
	{
		return $this->table->generate();
	}
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值