LeLeLong系统的开发手册
开发示例
在这里提供一个前台开发示例,该示例也包含在源文件里面。
后台的二次开发示例就不需要提供了,因为框架源文件本身已经包含了后台程序,大家可以详细看看admin.class.php、adminGroup.class.php、menu.class.php等等。
想更好地运用LeLeLong框架进行二次开发,建议大家认真看看框架的核心文件和类文件。
<?php
/**
* Author : UD
* homepage : http://www.lelelong.com
* Email : ultrawind@foxmail.com
*/
class ExampleClass extends Application
{
protected $web_title = 'example';
//是否使用数据缓存
protected $is_data_cache = true;
//显示静态html的action,比如index这个action包含在$show_html_arr里面了,那么执行index的时候框架会自动生成相应的静态html文件。不声明该属性,则不使用静态html
protected $show_html_arr = array('index');
//生成的静态html文件永不过期的action,不声明该属性,则html会过期重新生成,sys_config文件里有html过期时间设置
protected $alway_show_html = array('index');
//act所会到的$_GET合法变量,不设置则不判断$_GET变量是否合法
protected $act_can_get_arr = array('index' => array('page','language'));
/**
* 构造函数
*/
public function __construct() {
parent::__construct();
if(isset($this->show_html_arr) && in_array(CURRENT_ACT,$this->show_html_arr)) $this->is_show_html = true;
if(isset($this->alway_show_html) && in_array(CURRENT_ACT,$this->alway_show_html)) CacheHtml::$html_cache_second = 0;
}
public function index() {
/*
多语言开发示例:
在网站首页页面上让用户选择语言即可,用户选择之后,框架根据用户的选择来保存语言cookie的值。
在project_config.php中定义lang
$this->project_config['lang'] = array(1 => 'English', 2 => '简体中文', 3=> '繁體中文');
*/
//包含页面配置文件
require_once(CONFIG_DIR.'project_config.php');
//数据库操作,详情请看db.class.php,熟悉数据库类后开发更加得心应手
$search_sql = 'id>1';
$order_by = 'id desc';
//总数据数目,并且使用数据缓存
$total_row = $this->getTotalRow('example',$search_sql,$this->is_data_cache);
//包含翻页类文件,pageHtml.class.php一般用于前台翻页,方便搜索引擎收录网站内容,page.class.php一般用于后台ajax翻页
require_once(CLASS_DIR.'pageHtml.class.php');
//声明翻页类
$page = new PageHtml($total_row);
$this->page_info = $page->getNav();
//查询数据,并且使用数据缓存
$this->grid_data = $this->find('example',$search_sql,'id,title,content',$order_by,$page->page_offset,$page->page_per_row,$this->is_data_cache);
//更多的数据库操作示例:
//插入数据
$this->insert_id = $this->insertData('example',array('title' => 'hello','content' => 'insert_test'));
//查询一条数据
$this->rs = $this->findOne('example','id='.$this->insert_id);
//更新数据
$this->updateData('example',array('title' => 'world'),'id='.$this->insert_id);
//查询数据
$this->rs2 = $this->find('example','id='.$this->insert_id,'title','id desc',0,5,'fetch_assoc');
//查询所有数据
$this->rs3 = $this->findAll('example','id>5');
//通过sql查询数据
$this->rs4 = $this->findBySql('select * from '.DB_PREFIX.'example');
//获得总数据数量
$this->rs5 = $this->getTotalRow('example');
//删除数据
$this->rs6 = $this->deleteData('example','id='.$this->insert_id);
//通过sql获得总数据数量
$this->rs7 = $this->getTotalRowBySql('select count(*) as cnt from '.DB_PREFIX.'example');
//获得字段信息
$this->rs8 = $this->getFields('example');
//执行sql语句
$this->exeSql('select * from '.DB_PREFIX.'example');
/**************** 多数据库连接示例 ****************
//如果不想使用数据缓存,则$this->is_data_cache = false;即可
$this->is_data_cache = false;
//这里建立一个mysql连接到另外一个数据库test,test库中有game表。当然,数据库配置你可以写在db_config.php当中
$this->db_new = $this->connDB(array('type' => 'mysql','host' => 'localhost','user' => 'root','password' => '123456','database' => 'test'));
//多数据库操作示例:
$this->insert_id_new = $this->insertData('game',array('name' => 'insert_db_new'),$this->db_new);
$this->rs_new = $this->findOne('game','id='.$this->insert_id_new,'','',$this->is_data_cache,$this->db_new);
$this->updateData('game',array('name' => 'update_db_new'),'id='.$this->insert_id_new,$this->db_new);
$this->rs2_new = $this->find('game','id='.$this->insert_id_new,'','id desc','','',$this->is_data_cache,$this->db_new);
$this->rs3_new = $this->findAll('game','id=1','','',$this->is_data_cache,$this->db_new);
$this->rs4_new = $this->getTotalRow('game','','',$this->is_data_cache,$this->db_new);
$this->rs5_new = $this->deleteData('game','id='.$this->insert_id_new,$this->db_new);
$this->rs6_new = $this->getTotalRowBySql('select count(*) as cnt from le_game',$this->is_data_cache,$this->db_new);
$this->rs7_new = $this->getFields('game',$this->is_data_cache,$this->db_new);
$this->exeSql('select * from le_game',$this->db_new);
************************************************************/
}
}
?>