- 浏览: 3322434 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (567)
- Web前端-html/表单 (19)
- Web前端-CSS (24)
- Web前端-CSS框架 (4)
- Web前端-JS语言核心 (50)
- Web前端-JS客户端 (26)
- nodejs生态+grunt (10)
- seajs和requirejs (9)
- backbone等框架 (7)
- 模板基础 (7)
- Web前端-deps(不改动) (6)
- Web前端-component (10)
- Web前端-jquery-plugin (13)
- 浏览器兼容性 (6)
- Web前端-使用jQuery (25)
- Web前端-使用jqueryui (6)
- Web前端-性能优化 (3)
- Web协议-HTTP (6)
- ExtJS (13)
- PHP (22)
- PHP面向对象 (4)
- PHP扩展-SOAP (6)
- PHP扩展-curl (4)
- PHP与HTML(导出) (5)
- PHP扩展-综合 (7)
- mysql基础应用 (18)
- 技术心情 (18)
- 算法和面试题 (17)
- 工具(开发)使用 (36)
- memcached原理 (2)
- session和cookie (4)
- UML (2)
- Web前端_FusionCharts (5)
- Web前端_Flex (4)
- Web前端_JSP (3)
- JavaSE (10)
- JavaEE (4)
- tomcat (2)
- Servlet开发 (3)
- Spring开发 (1)
- REST相关 (2)
- 大访问量、高并发 (2)
- 网络编程 (1)
- YII (21)
- linux命令和内核 (12)
- yii与数据库 (10)
- yii与表单 (12)
- yii view层 (1)
- perl (7)
- yii扩展 (7)
- shell (4)
- photoshop (7)
- 视觉设计 (2)
- 我关注的名人在路上 (4)
- 1-自学能力 (1)
- 2-人际沟通能力 (3)
- 3-职业规划能力 (7)
- 4-项目管理能力 (2)
- python (3)
- django (4)
- Mysql高级应用 (6)
- prototype.js (4)
- Web系统安全 (1)
- Web前端-mobile (2)
- egret (6)
- jQuery源码分析 (5)
- fis (4)
最新评论
-
yzq21056563:
感谢作者分享~请教下,http://www.lisa33xia ...
CSS基础:text-overflow:ellipsis溢出文本 -
u012206458:
$.ajax的error,complete,success方法 -
DEMONU:
谢谢,虽然不能给你赞助,但是要给你顶
mysql中key 、primary key 、unique key 与index区别 -
njupt_tolmes:
阿凡达阿凡达阿凡达阿凡达阿凡达阿凡达阿凡达阿凡达阿凡达阿滕庆亚 ...
CSS基础:text-overflow:ellipsis溢出文本 -
zenmshuo:
用过SpreadJS,也包含数据可视化的图表
推荐几个web中常用js图表插件
作者:zccst
常用的用法是
this->user->isGuest;
this->user->id;
this->user->name;
还有设置session
this->user->setStatus('xx');
this->user->getStatus('xx');
查看一下手册后,发现user的属性和方法还真多。
详细如下:
CWebUser represents the persistent state for a Web application user.
CWebUser is used as an application component whose ID is 'user'. Therefore, at any place one can access the user state via
Yii::app()->user.
CWebUser should be used together with an identity which implements the actual authentication algorithm.
A typical authentication process using CWebUser is as follows:
1.The user provides information needed for authentication.
2.An identity instance is created with the user-provided information.
3.Call IUserIdentity::authenticate to check if the identity is valid.
4.If valid, call CWebUser::login to login the user, and Redirect the user browser to returnUrl.
5.If not valid, retrieve the error code or message from the identity instance and display it.
The property id and name are both identifiers for the user. The former is mainly used internally (e.g. primary key), while the
latter is for display purpose (e.g. username). The id property is a unique identifier for a user that is persistent during the
whole user session. It can be a username, or something else, depending on the implementation of the identity class.
Both id and name are persistent during the user session. Besides, an identity may have additional persistent data which can be
accessed by calling getState. Note, when cookie-based authentication is enabled, all these persistent data will be stored in
cookie. Therefore, do not store password or other sensitive data in the persistent storage. Instead, you should store them
directly in session on the server side if needed.
1,属性
allowAutoLogin boolean whether to enable cookie-based login. CWebUser
authTimeout integer timeout in seconds after which user is logged out if inactive. CWebUser
autoRenewCookie boolean whether to automatically renew the identity cookie each time a page is requested. CWebUser
autoUpdateFlash boolean whether to automatically update the validity of flash messages. CWebUser
behaviors array the behaviors that should be attached to this component. CApplicationComponent
flashes array Returns all flash messages. CWebUser
guestName string the name for a guest user. CWebUser
id mixed the unique identifier for the user. CWebUser
identityCookie array the property values (in name-value pairs) used to initialize the identity cookie. CWebUser
isGuest boolean whether the current application user is a guest. CWebUser
isInitialized boolean Checks if this application component bas been initialized. CApplicationComponent
loginUrl string|array the URL for login. CWebUser
name string Returns the unique identifier for the user (e.g. username). CWebUser
returnUrl string Returns the URL that the user should be redirected to after successful login. CWebUser
stateKeyPrefix string a prefix for the name of the session variables storing user session data. CWebUser
2,方法
最基本的方法
除了call, get, isset, set, unset方法之外,还有
getIsInitialized() Checks if this application component bas been initialized. //一般不需要检查
checkAccess() Performs access check for this user. //检查用户可以访问的操作
方法原型:public boolean checkAccess(string $operation, array $params=array ( ), boolean $allowCaching=true)
基本方法
getId() Returns the unique identifier for the user. If null, it means the user is a guest.
setId() Sets the unique identifier for the user. If null, it means the user is a guest.
getName() Returns the unique identifier for the user (e.g. username).
setName() Sets the unique identifier for the user (e.g. username).
setReturnUrl() Sets the URL that the user should be redirected to after login.
getReturnUrl() Returns the URL that the user should be redirected to after successful login.
canGetProperty() Determines whether a property can be read.
canSetProperty() Determines whether a property can be set.
登陆相关
login() Logs in a user. CWebUser
loginRequired() Redirects the user browser to the login page.//该方法非常好用
logout()
getIsGuest()
增加行为相关
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component.
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component.
session相关
setState() Stores a variable in user session. // 是基于cookie-based authentication,所以不应存一些如密码等敏感信息
getState() Returns the value of a variable that is stored in user session.
hasState() Returns a value indicating whether there is a state of the specified name.
clearStates() Clears all user identity information from persistent storage.
setStateKeyPrefix() Sets a prefix for the name of the session variables storing user session data.
getStateKeyPrefix() Returns a prefix for the name of the session variables storing user session data.
flash相关
hasFlash() Determines whether the specified flash message exists
getFlash() Returns a flash message.
setFlash() Stores a flash message.
getFlashes() Returns all flash messages.
事件相关
raiseEvent() Raises an event.
hasEvent() Determines whether an event is defined.
hasEventHandler() Checks whether the named event has attached handlers.
getEventHandlers() Returns the list of attached event handlers for an event.
attachEventHandler() Attaches an event handler to an event.
detachEventHandler() Detaches an existing event handler.
如果您觉得本文的内容对您的学习有所帮助,您可以微信:
常用的用法是
class Controller extends CController { public $user = null; $this->user = Yii:app()->user; }
this->user->isGuest;
this->user->id;
this->user->name;
还有设置session
this->user->setStatus('xx');
this->user->getStatus('xx');
查看一下手册后,发现user的属性和方法还真多。
详细如下:
CWebUser represents the persistent state for a Web application user.
CWebUser is used as an application component whose ID is 'user'. Therefore, at any place one can access the user state via
Yii::app()->user.
CWebUser should be used together with an identity which implements the actual authentication algorithm.
A typical authentication process using CWebUser is as follows:
1.The user provides information needed for authentication.
2.An identity instance is created with the user-provided information.
3.Call IUserIdentity::authenticate to check if the identity is valid.
4.If valid, call CWebUser::login to login the user, and Redirect the user browser to returnUrl.
5.If not valid, retrieve the error code or message from the identity instance and display it.
The property id and name are both identifiers for the user. The former is mainly used internally (e.g. primary key), while the
latter is for display purpose (e.g. username). The id property is a unique identifier for a user that is persistent during the
whole user session. It can be a username, or something else, depending on the implementation of the identity class.
Both id and name are persistent during the user session. Besides, an identity may have additional persistent data which can be
accessed by calling getState. Note, when cookie-based authentication is enabled, all these persistent data will be stored in
cookie. Therefore, do not store password or other sensitive data in the persistent storage. Instead, you should store them
directly in session on the server side if needed.
1,属性
allowAutoLogin boolean whether to enable cookie-based login. CWebUser
authTimeout integer timeout in seconds after which user is logged out if inactive. CWebUser
autoRenewCookie boolean whether to automatically renew the identity cookie each time a page is requested. CWebUser
autoUpdateFlash boolean whether to automatically update the validity of flash messages. CWebUser
behaviors array the behaviors that should be attached to this component. CApplicationComponent
flashes array Returns all flash messages. CWebUser
guestName string the name for a guest user. CWebUser
id mixed the unique identifier for the user. CWebUser
identityCookie array the property values (in name-value pairs) used to initialize the identity cookie. CWebUser
isGuest boolean whether the current application user is a guest. CWebUser
isInitialized boolean Checks if this application component bas been initialized. CApplicationComponent
loginUrl string|array the URL for login. CWebUser
name string Returns the unique identifier for the user (e.g. username). CWebUser
returnUrl string Returns the URL that the user should be redirected to after successful login. CWebUser
stateKeyPrefix string a prefix for the name of the session variables storing user session data. CWebUser
2,方法
最基本的方法
除了call, get, isset, set, unset方法之外,还有
getIsInitialized() Checks if this application component bas been initialized. //一般不需要检查
checkAccess() Performs access check for this user. //检查用户可以访问的操作
方法原型:public boolean checkAccess(string $operation, array $params=array ( ), boolean $allowCaching=true)
基本方法
getId() Returns the unique identifier for the user. If null, it means the user is a guest.
setId() Sets the unique identifier for the user. If null, it means the user is a guest.
getName() Returns the unique identifier for the user (e.g. username).
setName() Sets the unique identifier for the user (e.g. username).
setReturnUrl() Sets the URL that the user should be redirected to after login.
getReturnUrl() Returns the URL that the user should be redirected to after successful login.
canGetProperty() Determines whether a property can be read.
canSetProperty() Determines whether a property can be set.
登陆相关
login() Logs in a user. CWebUser
loginRequired() Redirects the user browser to the login page.//该方法非常好用
logout()
getIsGuest()
增加行为相关
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component.
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component.
session相关
setState() Stores a variable in user session. // 是基于cookie-based authentication,所以不应存一些如密码等敏感信息
getState() Returns the value of a variable that is stored in user session.
hasState() Returns a value indicating whether there is a state of the specified name.
clearStates() Clears all user identity information from persistent storage.
setStateKeyPrefix() Sets a prefix for the name of the session variables storing user session data.
getStateKeyPrefix() Returns a prefix for the name of the session variables storing user session data.
flash相关
hasFlash() Determines whether the specified flash message exists
getFlash() Returns a flash message.
setFlash() Stores a flash message.
getFlashes() Returns all flash messages.
事件相关
raiseEvent() Raises an event.
hasEvent() Determines whether an event is defined.
hasEventHandler() Checks whether the named event has attached handlers.
getEventHandlers() Returns the list of attached event handlers for an event.
attachEventHandler() Attaches an event handler to an event.
detachEventHandler() Detaches an existing event handler.
如果您觉得本文的内容对您的学习有所帮助,您可以微信:
发表评论
-
Yii隐藏index.php文件的步骤
2014-06-14 14:03 12039作者:zccst 1.修改Apache的配置httpd.co ... -
YII异常处理actionError
2014-06-14 08:47 1981zccst转 错误处理目录 1,引发异常 2,显示错误 3, ... -
YII之 redirect 与contoller之间的方法调用
2014-05-31 18:44 11340作者:zccst 一个contoller里怎么调用另一个co ... -
yii中设置默认时区和语言
2013-04-24 16:28 3528作者:zccst 把php从5.2升级到5.4后,发现5. ... -
Yii异常解决办法
2013-04-23 17:15 1191作者:zccst 在Yii的项目中有一个../protect ... -
Yii之HttpRequest相关
2012-08-16 18:35 5123作者:zccst yii中的HttpRequest很像Jav ... -
yii之Log(日志)使用
2012-06-07 19:17 24953作者:zccst Yii 提供了 ... -
Yii之urlManager相关
2012-03-31 13:04 7115作者:zccst 首先urlManager是CUrlMan ... -
yii框架的执行过程
2012-03-11 14:09 3781作者:zccst 二、controllers里的$this ... -
Yii中引入module
2012-03-11 14:06 4974作者:zccst 一、controller与layout/ ... -
如何在纯js文件中设置yii方式的url地址
2012-02-20 20:56 3342作者:zccst 1,在siteController.ph ... -
Yii使用filter进行访问控制
2012-02-16 19:23 15019Yii使用filter进行访问控制 作者:zccst 在Co ... -
Yii控制层处理结果返回前端的三种方式(render)
2012-01-12 16:28 31356Yii控制层处理结果返回前端的三种方式 作者:zccst ... -
Yii之widget专题
2012-01-12 16:14 11557作者:zccst 关于widgets ... -
Yii中使用session防止重复提交
2012-01-09 12:13 3216表单提交时,由于网速等原因,会出现重复提交的现象。 一、从前 ... -
yii中引入js和css文件
2011-12-29 20:10 35680作者:zccst 四、在视图层(../views/..)添加 ... -
Yii设置分页
2011-12-11 16:41 46261,在../models/NewDemand.php中定义pa ... -
在yii中使用session和cookie
2011-12-08 09:41 17325作者:zccst 2014-6-10 yii 操作sess ... -
Yii中引入php文件及插件
2011-11-03 14:32 24578作者:zccst 一、设置环境变量(在PHP) echo g ... -
YII初步
2011-06-03 22:19 2408安装过程,文档里有。 一、搭建Yii环境可能遇到的问题 1, ...
相关推荐
写在 yii2/backbone 上的 vk 应用模板 如何设置 克隆; chmod 0777 运行时; chmod 0777 网络/资产; 创建数据库; ... 通过在终端输入“./yii migrate”来创建用户表;...\Yii:$app->user->identiry->las
5. **权限检查**:在控制器或视图中,可以使用`Yii::$app->user->can`方法检查当前用户是否具有执行特定操作的权限。 6. **自定义权限管理模块**:如果默认的RBAC组件不能满足需求,可以编写自定义模块,扩展其功能...
此时,可以调用`Yii::app()->user->login`方法使用户登录系统。 接下来我们深入探讨`Yii::app()->user->login`方法的具体实现。该方法定义在`CWebUser`类中,主要负责以下几个关键步骤: 1. **更改用户身份**:...
echo Yii::app()->user->returnUrl; ``` 这通常用于重定向用户回到他们之前访问的页面。 获取根目录地址(不包括域名)则使用: ```php echo Yii::app()->homeUrl; ``` 而获取基于基URL的路径(例如,不含域名的...
->andFilterWhere(['user_id' => $this->user_id]) ->andFilterWhere(['customer_id' => $this->customer_id]) ->andFilterWhere(['order_time' => $this->order_time]) ->andFilterWhere(['pay_time' => $this-...
3. 使用:在控制器中,可以使用`Yii::app()->user->checkAccess()`方法来检查当前用户是否有执行某个操作的权限。例如: ```php if (Yii::app()->user->checkAccess('updatePost', array('postId' => $id))) { // ...
7. **权限检查**:在控制器或视图中,可以使用`can()`方法检查当前用户是否有执行某个操作的权限,如`if (Yii::$app->user->can('editPost')) { ... }`。 8. **数据库表结构**:使用`DbManager`时,框架会自动创建`...
6. **使用 RBAC**:在控制器或视图中,你可以使用 `Yii::$app->user->can()` 方法检查当前用户是否有执行特定操作的权限。如果用户有权限,方法将返回 `true`,反之则返回 `false`。 7. **动态添加和管理**:在运行...
$operator = Yii::$app->user->id; if ($owner != $operator) { $res['errmsg'] = '您删除的图片不存在'; return $res; } $trans = Yii::$app->db->beginTransaction(); try { $delstatus = Yii::$app->db...
5. 获取用户IP地址等其他相关信息,使用`$request->userIP`。 以上就是Yii框架通过请求组件处理GET和POST请求的核心知识点和操作技巧。为了更好地利用Yii框架开发高质量的PHP Web应用,开发者可以参考本文所述方法...
Yii框架是一个高性能的PHP开发框架,广泛用于Web应用的...开发者在应用Yii框架开发Web应用时,应充分考虑分页的用户体验和系统性能,充分利用Yii框架提供的分页组件和相关参数配置,为用户提供流畅且高效的分页体验。
if (Yii::app()->user->checkAccess('export')) { echo '<div class="toolBar">'; echo CHtml::beginForm(CHtml::normalizeUrl(array('actionExport')), 'post'); // 添加其他隐藏字段以传递必要参数 echo C...
跳转到`/admin/assignment/index`,在这里为当前用户分配刚创建的角色,而不是直接分配权限。这样,用户就拥有了“用户管理”的角色权限。 6. **菜单管理(Menu)**: 如果希望“用户管理”显示在后台菜单上,...
Yii::app()->user->id . Yii::app()->user->name . Yii::app()->user->mihome : $uniqueid; $token = md5("wms_check_repeat" . $uniqueid); $time = time(); if (isset($_SESSION['token']) && !empty($_...
`$this->context`可以获取当前的Module、Controller和Action;通过配置可以设置默认的Controller和Action;验证码、分页组件、自定义用户认证模型以及文件上传等都是Yii2.0框架常用的组件,它们都有丰富的API和示例...
$user = User::model()->find(array( 'select' => array('username', 'id', 'email'), 'order' => 'id DESC', 'condition' => 'id=:id', 'params' => array(':id' => $id), )); ``` 这里的 `condition` ...
$userList = User::model()->findAll($criteria); // 查询所有数据 $this->render('test', array('list' => $userList, 'pages' => $pager)); // 渲染视图 } ``` 这段代码实现了以下几个关键步骤: 1. **创建查询...
'items' => MenuHelper::getAssignedMenu(Yii::$app->user->id, null, $callback), ]); ``` 这样,我们就能够确保左侧菜单能够根据当前控制器高亮相应的菜单项,包括其父级菜单项。需要注意的是,文章中也提到了...
$this->user_id = Yii::app()->user->id; // 设置默认值为当前用户ID return true; // 返回true以确保数据能被保存 } ``` 在这个示例中,`user_id`字段将被设置为当前用户的身份ID。`beforeSave()`方法必须返回`...
2. **app()**: 这个函数返回`Yii::app()`,它是Yii框架的核心组件,提供了对应用程序级别的属性和方法的访问,如用户身份(`Yii::app()->user`)、参数(`Yii::app()->params`)等。 3. **cs()**: 这个函数返回`Yii...