<?php
/* SVN FILE: $Id: app_controller.php 7296 2008-06-27 09:09:03Z gwoo $ */
/**
*
* @filesource
* @copyright Copyright 2008-2009, lesorb, Inc.
* @link http://www.lesorb.cn Blog Project
* @package app
* @subpackage app
* @version $Revision: 1.1 $
* @author WangLiJun
* @lastmodified $2009-4-20$
*/
/**
* This is a placeholder class.
* Create the same file in app/app_controller.php
*
* Add your application-wide methods in the class below, your controllers
* will inherit them.
*
* @package cake
* @subpackage cake.cake.libs.controller
*/
class AppController extends Controller {
var $helpers = array('Html', 'Form', 'Javascript', 'Ajax');
var $components = array('RequestHandler', 'Acces', 'Cookie', 'Post');
function beforeFilter()
{
if(isset($this->params['prefix']) && ($this->params['prefix'] === 'manage')){
if($this->params['action'] === 'manage_add') {
if(!empty($this->data)) {
$this->Post->savePost($this->data);
$this->Acces->checkSession();
} else {
$this->data = $this->Post->getPost();
}
return;
}
$this->Acces->checkSession();
$this->layout = 'manage';
$this->setUserMsgSession($this->getUidBySession());
}
if (isset($this->params[Configure::read('Routing.admin')])) {
$this->Acces->checkAdmin();
$this->layout = 'admin';
}
if ($this->RequestHandler->isAjax()) {
$this->autoLayout = false;
Configure::write('debug', 0);
}
}
function renderError($message){
$this->set('message', $message);
// Render error view
$this->render(null, null, VIEWS . 'errors' . DS . 'error.ctp');
}
/**
* @method æ ¹æ®sessionæ£æ¥ç¨(å)æ·æ¯å¦å·²ç»ç»éï¼å¹¶ååºuid
* @name getUidBySession
* @Param none
* @return interger user_id
*/
function getUidBySession() {
if($this->Session->check('Users'))
return (int)$this->Session->read('Users.id');
return 0;
}
function getUserMsgNums() {
$this->loadModels('Commmessage');
$msgNum = $this->Commmessage->find('count',array('conditions'=>array('mtype'=>0,'ruid'=>$this->getUidBySession(),'isstrore'=>0)));
$this->Session->write('Message.msgNum', intval($msgNum));
}
/**
* @desc å è½½æå®æ¨¡å
* @name loadModels
* @param array/string, boolean, array('modelName', false)
* @return none;
*/
function loadModels($models, $bool = false)
{
if(!is_array($models)) {
$models = array($models);
}
foreach($models as $model) {
App::import('Model', $model);
$this->{$model} =& new $model();
if($bool) {
if($this->{$model}->hasOne) {
$hasOneModel = array_keys($this->{$model}->hasOne);
$this->{$model}->unbindAndPushModels(array('hasOne'=>$hasOneModel));
}
if($this->{$model}->belongsTo) {
$belongsToModel = array_keys($this->{$model}->belongsTo);
$this->{$model}->unbindAndPushModels(array('belongsTo'=>$belongsToModel));
}
if($this->{$model}->hasMany) {
$hasManyModel = array_keys($this->{$model}->hasMany);
$this->{$model}->unbindAndPushModels(array('hasMany'=>$hasManyModel));
}
}
}
}
}
?>