ITeye博客

cakephp开发前期准备一

lesorb · 2010-07-29 15:10 · cakephp · 编程语言 · Markdown

首先:在app目录下定义全局文件. 一般需要定义的app文件主要有: app_controller.php app_helper.php app_model.php...

1 app_controller.php文件主要注意: 注意$helpers(可能经常在view层使用到的helpers文件) 和 $components(可能经常使用到的系统组件包扩自定义)两个全局变量 ,如下:


/**
 * Controller 所使用的 Helper
 *
 * @var array
 * @access public
 */
var $helpers = array('Html', 'Form', 'Javascript', 'Ajax', 'GoogleMap', '...');
/**
 * Controller 所使用的 Components
 *
 * @var array
 * @access public
 */
var $components	= array('RequestHandler', 'Acces', 'Cookie', 'Post');

2 app_model.php文件主要注意: 由于历史的原因,假定本系列的mysql建立,都基于utf-8字符,则应该在查询前声明字符集,以保证结果显示正确的编码,如下:

      
/*
* construct method:低于 php5
*
* @access public
*/
	function AppModel(){
		$this->query('SET NAMES utf8');
	}
/*
* construct method:高于 php4
*
* @access public
*/
	function __construct(){	
		parent::__construct();
		$this->query('SET NAMES utf8');
	}

其它,再酢情定义一些,model层需要使用到的全局函数.譬如:重写beforeFind等等... 3 app_helper.php文件主要注意 引用或定义某些全局性的在view层可能经常使用到的函数.譬如 时间格式处理 formatdate 等.

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。