扩展Codeigniter控制器

<?php
class MY_Controller extends CI_Controller {

	 public function __construct() {
		parent::__construct();
		if(intval($this->session->userdata('id')) == 0)
			redirect(site_url('login/index'));
	}

    //前台加载视图方法
	public function _template($template, $data = array()){
		$data['nav'] = $this->get_left();
		$data['tpl'] = $template;
		$this->get_top($data);
		$this->load->view('default',$data);
	}

	public function get_left(){
		$menu = $this->config->item('menu');
		$nav = array();
		foreach ($menu as $key => $value) {
				$nav[$key]['class']	=	$value['class'];
				$nav[$key]['url']		=	$value['url'];
				$nav[$key]['name']	=	$value['name'];
				if( ! empty($value['child']))
					$nav[$key]['child']	=	$value['child'];
			}
		return $nav;
	}

	public function get_top($data){
		$this->load->view('top',$data);
	}

	/**
	 * page 分页
	 * @param  [type]  $base_url [分页URL带参数]
	 * @param  [type]  $total    [总记录数]
	 * @param  integer $type     [类型 0:无搜索,1:带搜索条件]
	 * @param  integer $per_page [每页显示记录数]
	 * @return []            [description]
	 */
	public function page($base_url,$total,$type=0,$per_page=12)
	{

		$this->load->library('pagination');
		$config['base_url'] = $base_url;
		$config['total_rows'] = $total;
		$config['per_page'] = $per_page; 
		$config['use_page_numbers'] = TRUE;  //1
		if($type > 0)
		{
			parse_str($_SERVER['QUERY_STRING'], $_GET);
			$config['page_query_string'] = TRUE; //get
		}
		$config['first_link'] = '首页';
		$config['last_link'] = '末页';
		$config['next_link'] = '下一页';
		$config['prev_link'] = '上一页';
		$config['cur_tag_open'] = '<span class="current">';
		$config['cur_tag_close'] = '</span>';

		// $config['num_tag_open'] = '<a>';
		// $config['num_tag_close'] = '</a>';

		$this->pagination->initialize($config); 

		//return $this->pagination->create_links();
	}

	/**
	 * um 加载编辑器 百度
	 * @param  [string]  $info   [须要默认显示的内容]
	 * @param  integer $width  [宽度]
	 * @param  integer $height [调试]
	 * @return string[type]          [返回内容]
	 */
	public function um($info,$name="content",$width=800,$height=300)
	{
		$um = '';
		$um .= '<link href="/source/um/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">';
	    $um .= '<script type="text/javascript" src="/source/um/third-party/jquery.min.js"></script>';
	    $um .= '<script type="text/javascript" charset="utf-8" src="/source/um/umeditor.config.js"></script>';
	    $um .= '<script type="text/javascript" charset="utf-8" src="/source/um/umeditor.min.js"></script>';
	    $um .= '<script type="text/javascript" src="/source/um/lang/zh-cn/zh-cn.js"></script>';
		$um .= '<script type="text/plain" id="myEditor" name="'.$name.'" style="width:'.$width.'px;height:'.$height.'px;"><p>'.$info.'</p></script>';
		$um .= '<script type="text/javascript">var um = UM.getEditor("myEditor"); </script>';
		return $um;
	}

}




/**
 * @author [author] <[[email protected]]>
 * /admin/core/MY_Controller.php
 */



你可能感兴趣的:(扩展CI控制器)