'modules'=>array(
'admin'=>array(//这行的admin为Module ID。与创建Module时填写的Module ID大写写一致
'class'=>'application.modules.admin.AdminModule',//这里的admin在windows os中大小写无所谓,但最好与实际目录一致。
),
),
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),//表示任意用户可访问index、view方法
'users'=>array('*'),//表示任意用户
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),//表示只有认证用户才可操作create、update方法
'users'=>array('@'),//表示认证用户
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),//表示只有用户admin才能访问admin、delete方法
'users'=>array('admin'),//表示指定用户,这里指用户:admin
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
public function beforeSave()
{
if(parent::beforeSave())
{
if($this->isNewRecord)
{
$this->password=md5($this->password);
$this->create_user_id=Yii::app()->user->id;//一开始这样写,User::model()->user->id;(错误)
//$this->user->id;(错误)
$this->create_time=date('Y-m-d H:i:s');
}
else
{
$this->update_user_id=Yii::app()->user->id;
$this->update_time=date('Y-m-d H:i:s');
}
return true;
}
else
{
return false;
}
}
<?php
/**
* UserIdentity represents the data needed to identity a user.
* It contains the authentication method that checks if the provided
* data can identity the user.
*/
class UserIdentity extends CUserIdentity
{
/**
* Authenticates a user.
* The example implementation makes sure if the username and password
* are both 'demo'.
* In practical applications, this should be changed to authenticate
* against some persistent user identity storage (e.g. database).
* @return boolean whether authentication succeeds.
*/
private $_id;
public function authenticate()
{
$username=strtolower($this->username);
$user=User::model()->find('LOWER(username)=?',array($username));
if($user===null)
{
$this->errorCode=self::ERROR_USERNAME_INVALID;
}
else
{
//if(!User::model()->validatePassword($this->password))
if(!$user->validatePassword($this->password))
{
$this->errorCode=self::ERROR_PASSWORD_INVALID;
}
else
{
$this->_id=$user->id;
$this->username=$user->username;
$this->errorCode=self::ERROR_NONE;
}
}
return $this->errorCode===self::ERROR_NONE;
}
public function getId()
{
return $this->_id;
}
}
public function beforeSave()
{
if(parent::beforeSave())
{
if($this->isNewRecord)
{
$this->password=md5($this->password);
$this->create_user_id=Yii::app()->user->id;//====主要为此句。得到登陆帐号的ID
$this->create_time=date('Y-m-d H:i:s');
}
else
{
$this->update_user_id=Yii::app()->user->id;
$this->update_time=date('Y-m-d H:i:s');
}
return true;
}
else
{
return false;
}
}
/*
由于CComponent是post最顶级父类,所以添加getUrl方法。。。。如下说明:
CComponent 是所有组件类的基类。
CComponent 实现了定义、使用属性和事件的协议。
属性是通过getter方法或/和setter方法定义。访问属性就像访问普通的对象变量。读取或写入属性将调用应相的getter或setter方法
例如:
$a=$component->text; // equivalent to $a=$component->getText();
$component->text='abc'; // equivalent to $component->setText('abc');
getter和setter方法的格式如下
// getter, defines a readable property 'text'
public function getText() { ... }
// setter, defines a writable property 'text' with $value to be set to the property
public function setText($value) { ... }
*/
public function getUrl()
{
return Yii::app()->createUrl('post/view',array(
'id'=>$this->id,
'title'=>$this->title,
));
}
/*
* rules方法:指定对模型属性的验证规则
* 模型实例调用validate或save方法时逐一执行
* 验证的必须是用户输入的属性。像id,作者id等通过代码或数据库设定的不用出现在rules中。
*/
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('news_title, news_content', 'required'),
array('news_title', 'length', 'max'=>128),
array('news_content', 'length', 'max'=>8000),
array('author_name, type_id, status_id,create_time, update_time, create_user_id, update_user_id', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, news_title, news_content, author_name, type_id, status_id, create_time, update_time, create_user_id, update_user_id', 'safe', 'on'=>'search'),
);
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('news_title, news_content', 'required'),
array('news_title', 'length', 'max'=>128, 'encoding'=>'utf-8'),
array('news_content', 'length', 'max'=>8000, 'encoding'=>'utf-8'),
array('author_name', 'length', 'max'=>10, 'encoding'=>'utf-8'),
array('status_id, type_id', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, news_title, news_content, author_name, type_id, status_id', 'safe', 'on'=>'search'),
);
}
<?php
Yii::import('zii.widgets.CPortlet');
class Banner extends CPortlet
{
protected function renderContent()
{
$this->render('banner');
}
}
Yii::app()->request->getServerName();
//and
$_SERVER['HTTP_HOST'];
$url = 'http://'.Yii::app()->request->getServerName(); $url .= CController::createUrl('user/activateEmail', array('emailActivationKey'=>$activationKey));
echo $url;
$this->widget('application.extensions.editor.CKkceditor',array(
"model"=>$model, # Data-Model
"attribute"=>'news_content', # Attribute in the Data-Model
"height"=>'300px',
"width"=>'80%',
"filespath"=>Yii::app()->basePath."/../up/",
"filesurl"=>Yii::app()->baseUrl."/up/",
);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有