如何定制(中文化)Yii核心消息?

参考地址:How to customize Yii core messages?

修改config/main.php

return array(
    ......
    'language'=>'de',
    'components'=>array(
        'coreMessages'=>array(
            'basePath'=>null,
        ),
        ......
    ),
);

定义语言文件:

WebRoot/
    protected/
        messages/
            zh_cn/
                yii.php
                zii.php
        controllers/
        views/
        ......

下载修改后的语言文件(结束句号已经批量修改为全角):
yii.php


/**
 * Message translations.
 *
 * This file is automatically generated by 'yiic message' command.
 * It contains the localizable messages extracted from source code.
 * You may modify this file by translating the extracted messages.
 *
 * Each array element represents the translation (value) of a message (key).
 * If the value is empty, the message is considered as not translated.
 * Messages that no longer need translation will have their translations
 * enclosed between a pair of '@@' marks.
 *
 * NOTE, this file must be saved in UTF-8 encoding.
 *
 * @version $Id: yii.php 2879 2011-01-16 23:13:00Z qiang.xue $
 */
return array (
  'Active record class "{class}" does not have a scope named "{scope}".' => 'AR类 "{class}" 没有名为 "{scope}" 的命名范围。',
  'Alias "{alias}" is invalid. Make sure it points to an existing PHP file.' => '别名 "{alias}" 无效。请确认它指向一个存在的PHP文件。',
  'Alias "{alias}" is invalid. Make sure it points to an existing directory.' => '别名 "{alias}" 无效。请确认它指向一个存在的目录。',
  'Application Log' => '程序日志',
  'Base path "{path}" is not a valid directory.' => '基准路径 "{path}" 不是一个有效的目录。',
  'CDbCacheDependency.connectionID "{id}" is invalid. Please make sure it refers to the ID of a CDbConnection application component.' => 'CDbCacheDependency.connectionID "{id}" 无效。请确认它指向一个有效的CDbConnection应用组件的ID',
  'CDbConnection failed to open the DB connection.' => 'CDbConnection连接数据库失败',
  'CDbTestFixture.connectionID "{id}" is invalid. Please make sure it refers to the ID of a CDbConnection application component.' => 'CDbTestFixture.connectionID "{id}" 无效。请确认它指向一个有效的CDbConnection应用组件的ID',
  'CEAcceleratorCache requires PHP eAccelerator extension to be loaded, enabled or compiled with the "--with-eaccelerator-shared-memory" option.' => 'CEAcceleratorCache需要PHP的Accelerator扩展被调用,并且使用 "--with-eaccelerator-shared-memory" 选项启用或者编译。',
  'CTypedMap<{type}> can only hold objects of {type} class.' => 'CTypedMap<{type}>仅支持{type}类的对象。',
  'CWinCache requires PHP wincache extension to be loaded.' => 'CWinCache需要PHP的wincache扩展被调用。',
  'CWinCache user cache is disabled. Please set wincache.ucenabled to On in your php.ini.' => 'CWinCache用户缓存北京永。请在php.ini中设置wincache.ucenabled启用。',
  'CZendDataCache requires PHP Zend Data Cache extension to be loaded.' => 'CZendDataCache需要PHP的Zend Data Cache扩展被调用。',
  'Column name must be either a string or an array.' => '列名必须是一个字符串或者数组',
  'Extension path "{path}" does not exist.' => '扩展路径 "{path}" 不存在。',
  'Failed to initialize the mcrypt module.' => '初始化mcrypt模块失败。',
  'Failed to set unsafe attribute "{attribute}".' => '设置非安全(unsafe)属性 "{attribute}" 失败。',
  'GD and FreeType PHP extensions are required.' => 'PHP的GD和FreeType扩展需要被调用。',
  'Invalid operator "{operator}".' => '无效操作符 "{operator}"。',
  'Resetting PK sequence is not supported.' => '重置主键(PK)序列不支持。',
  'Setting integrity check is not supported.' => '设置完整性检查不支持。',
  'Table "{table}" does not exist.' => '数据表 "{table}" 不存在。',
  'The "range" property must be specified with a list of values.' => '"range" 属性必须用一个列表值设定。',
  'The STAT relation "{name}" cannot have child relations.' => 'STAT关联 "{name}" 不能有子关联。',
  'The module path "{path}" is not a valid directory.' => '模块路径 "{path}" 不是一个有效的路径。',
  'The pattern for day of the week must be "E", "EE", "EEE", "EEEE", "EEEEE", "e", "ee", "eee", "eeee", "eeeee", "c", "cccc" or "ccccc".' => '星期几的格式必须是 "E", "EE", "EEE", "EEEE", "EEEEE", "e", "ee", "eee", "eeee", "eeeee", "c", "cccc" 或者 "ccccc"。',
  'The pattern for month must be "M", "MM", "MMM", "MMMM", "L", "LL", "LLL" or "LLLL".' => '月份的格式必须是 "M", "MM", "MMM", "MMMM", "L", "LL", "LLL" 或者 "LLLL"。',
  'The relation "{relation}" in active record class "{class}" is not specified correctly. The join table "{joinTable}" given in the foreign key cannot be found in the database.'=>'AR类 "{class}" 的关联 "{relation}" 的设定不正确。通过外键连接的数据表 "{joinTable}" 在数据库中找不到。',
  'The relation "{relation}" in active record class "{class}" is specified with a foreign key "{key}" that does not point to the parent table "{table}".' => 'AR类 "{class}" 的关联 "{relation}" 设定的外键 "{key}" 没有指向父表 "{table}"。',
  'The relation "{relation}" in active record class "{class}" is specified with an invalid foreign key "{key}". There is no such column in the table "{table}".' => 'AR类 "{class}" 的关联 "{relation}" 设定了一个无效的外键 "{key}"。在数据表 "{table}" 中没有这样的列。',
  'The relation "{relation}" in active record class "{class}" is specified with an invalid foreign key. The columns in the key must match the primary keys of the table "{table}".' => 'AR类 "{class}" 的关联 "{relation}" 设定了一个无效的外键 "{key}"。该键的列必须是数据表 "{table}" 的主键。',
  'The requested view "{name}" was not found.' => '找不到请求的视图 "{name}"。',
  'The value for the column "{column}" is not supplied when querying the table "{table}".' => '查询数据表 "{table}" 时,不会提供列 "{column}" 的值。',
  'Unable to import "{alias}". Please check your server configuration to make sure you are allowed to change PHP include_path.' => '无法导入 "{alias}"。请检查您的服务器配置,以确保允许您的程序更改PHP的include_path设置。',
  'Unable to resolve the request "{route}".' => '无法解析请求 "{route}"。',
  'Unknown type "{type}".' => '未知类型 "{type}"。',
  'Your request is invalid.' => '您的请求无效。',
  '{attribute} "{value}" is invalid.' => '{attribute} "{value}" 无效。',
  '{attribute} cannot accept more than {limit} files.' => '{attribute} 仅接受 {limit} 个以内的文件。',
  '{attribute} is in the list.' => '{attribute} 在列表中',
  '{attribute} must be either {true} or {false}.' => '{attribute} 必须为{true}或者{false}',
  '{attribute} must be greater than "{compareValue}".' => '{attribute}必须大于 "{compareValue}"。',
  '{attribute} must be greater than or equal to "{compareValue}".' => '{attribute}必须大于或者等于 "{compareValue}"。',
  '{attribute} must be less than "{compareValue}".' => '{attribute}必须小于 "{compareValue}"。',
  '{attribute} must be less than or equal to "{compareValue}".' => '{attribute}必须小于或者等于 "{compareValue}"。',
  '{attribute} must be {value}.' => '{attribute}必须为{value}。',
  '{attribute} must not be equal to "{compareValue}".' => '{attribute}必须不等于"{compareValue}"。',
  '{className} does not support flushValues() functionality.' => '{className} 不支持 flushValues() 功能。',
  '{class} does not have a method named "{name}".' => '{class} 没有名为 "{name}" 的方法。',
  'CDbLogRoute requires database table "{table}" to store log messages.' => '@@CDbLogRoute 要求数据库 table "{table}" 储存日志讯息.@@',
  'CMemCache requires PHP memcache extension to be loaded.' => '@@CMemCache 要求 PHP memcache extension 必须先被载入.@@',
  'CMultiFileUpload.name is required.' => '@@CMultiFileUpload.name 是必要的.@@',
  'CSecurityManager.validation must be either "MD5" or "SHA1".' => '@@CSecurityManager.validation 必须是 "MD5" 或 "SHA1".@@',
  'Cache table "{tableName}" does not exist.' => '@@Cache table "{tableName}" 不存在.@@',
  'Table "{table}" does not have a primary key defined.' => '@@Table "{table}" 没有定义主键.@@',
  'The "view" property is required.' => '@@需要 "view" 属性@@',
  'The asset "{asset}" to be pulished does not exist.' => '@@欲发布的 asset "{asset}" 不存在.@@',
  'The column "{column}" is not a foreign key in table "{table}".' => '@@栏位 "{column}" 并不是 table "{table}" 中的一个 foreign key.@@',
  'The pattern for day of the week must be "E", "EE", "EEE", "EEEE" or "EEEEE".' => '@@代表 day of the week 的格式必须是 "E", "EE", "EEE", "EEEE" 或 "EEEEE".@@',
  'The pattern for month must be "M", "MM", "MMM", or "MMMM".' => '@@代表月份的格式必须是 "M", "MM", "MMM", 或 "MMMM".@@',
  'The relation "{relation}" in active record class "{class}" is specified with an invalid foreign key "{key}". The foreign key does not point to either joining table.' => '@@active record class "{class}" 中的关联 "{relation}" 有一个无效的 foreign key "{key}". foreign key 未指到任一个 joining table.@@',
  'The requested controller "{controller}" does not exist.' => '@@请求的控制器 "{controller}" 不存在.@@',
  'The requested view "{name}" is not found.' => '@@请求的 view "{name}" 未找到.@@',
  'The value for the primary key "{key}" is not supplied when querying the table "{table}".' => '@@查询 table "{table}" 时未提供 primary key "{key}" 的值.@@',
  'Unable to find the decorator view "{view}".' => '@@无法找到 decorator view "{view}".@@',
  'Unable to find the list item.' => '@@无法找到列表项目.@@',
  '{className} does not support flush() functionality.' => '@@{className} 不支持 flush() 功能.@@',
  '{class} does not have attribute "{name}".' => '@@{class} 中没有名为 "{name}" 的属性.@@',
  '"{path}" is not a valid directory.' => '"{path}" 不是一个合法的目录。',
  '&lt; Previous' => '&lt; 前页',
  '&lt;&lt; First' => '&lt;&lt; 首页',
  'Active Record requires a "db" CDbConnection application component.' => 'Active Record 需要一个名为 "db" 的 CDbConnection 应用程序组件。',
  'Active record "{class}" has an invalid configuration for relation "{relation}". It must specify the relation type, the related active record class and the foreign key.' => 'Active record "{class}" 对于关联 "{relation}" 有一个无效的配置. 必须给定关联种类, 相关的 active record class 以及 foreign key。',
  'Active record "{class}" is trying to select an invalid column "{column}". Note, the column must exist in the table or be an expression with alias.' => 'Active record "{class}" 正尝试选择一个无效的栏位 "{column}". 注意, 该栏位必须存在于 table 中或者是一个具别名的 expression。',
  'Alias "{alias}" is invalid. Make sure it points to an existing directory or file.' => '别名 "{alias}" 是无效的. 请确定它指向一个已存在的目录或文件。',
  'Application base path "{path}" is not a valid directory.' => '应用程序基准路径 "{path}" 是无效的目录。',
  'Application runtime path "{path}" is not valid. Please make sure it is a directory writable by the Web server process.' => '应用程序执行时的路径 "{path}" 是无效的. 请确定它是一个可被 Web server process 写入资料的目录。',
  'Authorization item "{item}" has already been assigned to user "{user}".' => '授权项目 "{item}" 已经被指派给使用者 "{user}"。',
  'CApcCache requires PHP apc extension to be loaded.' => 'CApcCache 要求 PHP apc extension 必须先被载入。',
  'CAssetManager.basePath "{path}" is invalid. Please make sure the directory exists and is writable by the Web server process.' => 'CAssetManager.basePath "{path}" 是无效的. 请确定它是一个可被 Web server process 写入资料的目录。',
  'CCacheHttpSession.cacheID is invalid. Please make sure "{id}" refers to a valid cache application component.' => 'CCacheHttpSession.cacheID 是无效的. 请确定 "{id}" 参照到一个有效的快取应用程序组件。',
  'CCaptchaValidator.action "{id}" is invalid. Unable to find such an action in the current controller.' => 'CCaptchaValidator.action "{id}" 是无效的. 无法在目前的控制器中找到此一动作。',
  'CDbAuthManager.connectionID "{id}" is invalid. Please make sure it refers to the ID of a CDbConnection application component.' => 'CDbAuthManager.connectionID "{id}" 是无效的. 请确定它参照到一个 CDbConnection 应用程序组件的 ID。',
  'CDbCache.connectionID "{id}" is invalid. Please make sure it refers to the ID of a CDbConnection application component.' => 'CDbCache.connectionID "{id}" 是无效的. 请确定它参照到一个 CDbConnection 应用程序组件的 ID。',
  'CDbCacheDependency.sql cannot be empty.' => 'CDbCacheDependency.sql 不能是空的。',
  'CDbCommand failed to execute the SQL statement: {error}' => 'CDbCommand 无法执行 SQL 语句: {error}',
  'CDbCommand failed to prepare the SQL statement: {error}' => 'CDbCommand 无法准备 SQL 语句: {error}',
  'CDbConnection does not support reading schema for {driver} database.' => 'CDbConnection 不支持对 {driver} 数据库 schema 的读取。',
  'CDbConnection failed to open the DB connection: {error}' => 'CDbConnection 无法开启数据库连线: {error}',
  'CDbConnection is inactive and cannot perform any DB operations.' => 'CDbConnection 状态为未启用, 无法进行任何数据库动作。',
  'CDbConnection.connectionString cannot be empty.' => 'CDbConnection.connectionString 不能是空的。',
  'CDbDataReader cannot rewind. It is a forward-only reader.' => 'CDbDataReader 无法倒回, 只允许向前读取。',
  'CDbHttpSession.connectionID "{id}" is invalid. Please make sure it refers to the ID of a CDbConnection application component.' => 'CDbHttpSession.connectionID "{id}" 是无效的. 请确定它参照到一个 CDbConnection 应用程序组件的 ID。',
  'CDbLogRoute.connectionID "{id}" does not point to a valid CDbConnection application component.' => 'CDbLogRoute.connectionID "{id}" 未指向一个有效的 CDbConnection 应用程序组件。',
  'CDbMessageSource.connectionID is invalid. Please make sure "{id}" refers to a valid database application component.' => 'CDbMessageSource.connectionID 是无效的. 请确定 "{id}" 参照到一个有效的数据库应用程序组件。',
  'CDbTransaction is inactive and cannot perform commit or roll back operations.' => 'CDbTransaction 状态为未启用, 无法进行 commit 或 roll back 动作。',
  'CDirectoryCacheDependency.directory cannot be empty.' => 'CDirectoryCacheDependency.directory 不能是空的。',
  'CFileCacheDependency.fileName cannot be empty.' => 'CFileCacheDependency.fileName 不能是空的。',
  'CFileLogRoute.logPath "{path}" does not point to a valid directory. Make sure the directory exists and is writable by the Web server process.' => 'CFileLogRoute.logPath "{path}" does not point to a valid directory. 请确定目录存在并且允许 Web server process 写入。',
  'CFilterChain can only take objects implementing the IFilter interface.' => 'CFilterChain 只能取得有实现 IFilter 接口的对象。',
  'CFlexWidget.baseUrl cannot be empty.' => 'CFlexWidget.baseUrl 不能是空的。',
  'CFlexWidget.name cannot be empty.' => 'CFlexWidget.name 不能是空的。',
  'CGlobalStateCacheDependency.stateName cannot be empty.' => 'CGlobalStateCacheDependency.stateName 不能是空的。',
  'CHttpCookieCollection can only hold CHttpCookie objects.' => 'CHttpCookieCollection 只能持有 CHttpCookie 对象。',
  'CHttpRequest is unable to determine the entry script URL.' => 'CHttpRequest 不能确认入口脚本的 URL。',
  'CHttpRequest is unable to determine the path info of the request.' => 'CHttpRequest 不能确认请求的路径信息。',
  'CHttpRequest is unable to determine the request URI.' => 'CHttpRequest 不能确认请求的 URI。',
  'CHttpSession.cookieMode can only be "none", "allow" or "only".' => 'CHttpSession.cookieMode 只能是 "none", "allow" 或 "only"。',
  'CHttpSession.gcProbability "{value}" is invalid. It must be an integer between 0 and 100.' => 'CHttpSession.gcProbability "{value}" 是无效的. 它必须是介于 0 与 100之间的整数。',
  'CHttpSession.savePath "{path}" is not a valid directory.' => 'CHttpSession.savePath "{path}" 不是一个有效的目录。',
  'CMemCache server configuration must be an array.' => 'CMemCache 服务器配置必须是一个数组。',
  'CMemCache server configuration must have "host" value.' => 'CMemCache 服务器配置必须有 "host" 的值。',
  'CProfileLogRoute found a mismatching code block "{token}". Make sure the calls to Yii::beginProfile() and Yii::endProfile() be properly nested.' => 'CProfileLogRoute found a mismatching code block "{token}". 请确定对于 Yii::beginProfile() 与 Yii::endProfile() 的呼叫是适当地巢状套叠的。',
  'CProfileLogRoute.report "{report}" is invalid. Valid values include "summary" and "callstack".' => 'CProfileLogRoute.report "{report}" 是无效的. 有效值包含 "summary" 与 "callstack"。',
  'CSecurityManager requires PHP mcrypt extension to be loaded in order to use data encryption feature.' => 'CSecurityManager 要求 PHP mcrypt extension 必须先被载入以便使用资料加密功能。',
  'CSecurityManager.encryptionKey cannot be empty.' => 'CSecurityManager.encryptionKey 不能是空的。',
  'CSecurityManager.validationKey cannot be empty.' => 'CSecurityManager.validationKey 不能是空的。',
  'CTypedList<{type}> can only hold objects of {type} class.' => 'CTypedList<{type}> 只能持有 {type} 类别的对象。',
  'CUrlManager.UrlFormat must be either "path" or "get".' => 'CUrlManager.UrlFormat 必须是 "path" 或 "get"。',
  'CXCache requires PHP XCache extension to be loaded.' => 'CXCache 要求 PHP XCache extension 必须先被载入。',
  'Cannot add "{child}" as a child of "{name}". A loop has been detected.' => '无法新增 "{child}" 成为 "{name}" 的子项. 侦测到有迴圈产生。',
  'Cannot add "{child}" as a child of "{parent}". A loop has been detected.' => '无法新增 "{child}" 成为 "{parent}" 的子项. 侦测到有迴圈产生。',
  'Cannot add "{name}" as a child of itself.' => '无法新增 "{name}" 成为它自己的子项。',
  'Cannot add an item of type "{child}" to an item of type "{parent}".' => '无法新增一个种类为 "{child}" 的项目到一个种类为 "{parent}" 的项目。',
  'Either "{parent}" or "{child}" does not exist.' => '"{parent}" 或 "{child}" 不存在。',
  'Error: Table "{table}" does not have a primary key.' => '错误: Table "{table}" 没有定义主键。',
  'Error: Table "{table}" has a composite primary key which is not supported by crud command.' => '错误: Table "{table}" 有一个不被 crud 命令所支持的合成主键。',
  'Event "{class}.{event}" is attached with an invalid handler "{handler}".' => '事件 "{class}.{event}" 附加了一个无效的 handler "{handler}"。',
  'Event "{class}.{event}" is not defined.' => '事件 "{class}.{event}" 未定义。',
  'Failed to write the uploaded file "{file}" to disk.' => '无法将已上传的文件 "{file}" 写入磁碟。',
  'File upload was stopped by extension.' => '文件上传被 extension 所停止。',
  'Filter "{filter}" is invalid. Controller "{class}" does have the filter method "filter{filter}".' => '筛选器 "{filter}" 是无效的. 控制器 "{class}" 没有名为 "filter{filter}" 的筛选器方法。',
  'Get a new code' => '取得一组新代码',
  'Go to page: ' => '翻页: ',
  'Invalid MO file revision: {revision}.' => '无效的 MO 文件修订: {revision}。',
  'Invalid MO file: {file} (magic: {magic}).' => '无效的 MO 文件: {file} (magic: {magic})。',
  'Invalid enumerable value "{value}". Please make sure it is among ({enum}).' => '无效的 enumerable 值 "{value}". 请确定它在 ({enum}) 之中。',
  'Last &gt;&gt;' => '末页 &gt;&gt;',
  'List data must be an array or an object implementing Traversable.' => '列表资料必须是一个数组或是有实现 Traversable 的一个对象。',
  'List index "{index}" is out of bound.' => '列表索引 "{index}" 超出范围。',
  'Login Required' => '需要先登入系统',
  'Map data must be an array or an object implementing Traversable.' => '哈希表资料必须是一个数组或一个实现 Traversable 的对象。',
  'Missing the temporary folder to store the uploaded file "{file}".' => '缺乏暂存目录来储存已上传的文件 "{file}"。',
  'Next &gt;' => '后页 &gt;',
  'No columns are being updated for table "{table}".' => 'table "{table}" 没有任何栏位将被更新。',
  'No counter columns are being updated for table "{table}".' => 'table "{table}" 没有任何计数器栏位将被更新。',
  'Object configuration must be an array containing a "class" element.' => '对象配置必须是内含有一个 "class" 元素的一个数组。',
  'Please fix the following input errors:' => '请更正下列输入错误:',
  'Property "{class}.{property}" is not defined.' => '属性 "{class}.{property}" 未被定义。',
  'Property "{class}.{property}" is read only.' => '属性 "{class}.{property}" 是只读的。',
  'Queue data must be an array or an object implementing Traversable.' => '队列资料必须是一个数组或一个实现 Traversable 的对象。',
  'Relation "{name}" is not defined in active record class "{class}".' => '关联 "{name}" 未被定义在 active record class "{class}" 中。',
  'Stack data must be an array or an object implementing Traversable.' => '堆栈资料必须是一个数组或一个实现 Traversable 的对象。',
  'Table "{table}" does not have a column named "{column}".' => 'Table "{table}" 没有名为 "{column}" 的栏位。',
  'The "filter" property must be specified with a valid callback.' => '属性 "filter" 必须以一个有效的 callback 指明。',
  'The "pattern" property must be specified with a valid regular expression.' => '属性 "pattern" 必须以一个有效的 regular expression 指明。',
  'The CSRF token could not be verified.' => 'CSRF token 无法被验证。',
  'The URL pattern "{pattern}" for route "{route}" is not a valid regular expression.' => 'route "{route}" 中的 URL 格式 "{pattern}" 不是有效的 regular expression。',
  'The active record cannot be deleted because it is new.' => 'active record 由于是新的, 无法被删除。',
  'The active record cannot be inserted to database because it is not new.' => 'active record 由于不是新的, 无法被新增到数据库。',
  'The active record cannot be updated because it is new.' => 'active record 由于是新的, 无法被更新。',
  'The asset "{asset}" to be published does not exist.' => 'Asset文件 "{asset}" 不存在。',
  'The command path "{path}" is not a valid directory.' => '命令路径 "{path}" 不是一个有效的目录。',
  'The controller path "{path}" is not a valid directory.' => '控制器路径 "{path}" 不是一个有效的目录。',
  'The file "{file}" cannot be uploaded. Only files with these extensions are allowed: {extensions}.' => '文件 "{file}" 无法被上传. 只有附档名如下的文件是被允许的: {extensions}。',
  'The file "{file}" is too large. Its size cannot exceed {limit} bytes.' => '文件 "{file}" 太大. 文件大小不能超过 {limit} 位元组。',
  'The file "{file}" is too small. Its size cannot be smaller than {limit} bytes.' => '文件 "{file}" 太小. 文件大小不能少于 {limit} 位元组。',
  'The file "{file}" was only partially uploaded.' => '文件 "{file}" 上传不完全。',
  'The first element in a filter configuration must be the filter class.' => '筛选器配置中的第一个元素必须是筛选器类别。',
  'The item "{name}" does not exist.' => '项目 "{name}" 不存在。',
  'The item "{parent}" already has a child "{child}".' => '项目 "{parent}" 已有子项目 "{child}"。',
  'The layout path "{path}" is not a valid directory.' => '布局路径 "{path}" 不是一个有效的目录。',
  'The list is read only.' => '列表是只读的。',
  'The map is read only.' => '哈希表是只读的。',
  'The pattern for 12 hour format must be "h" or "hh".' => '代表12小时制的格式必须是 "h" 或 "hh"。',
  'The pattern for 24 hour format must be "H" or "HH".' => '代表24小时制的格式必须是 "H" 或 "HH"。',
  'The pattern for AM/PM marker must be "a".' => '代表 AM/PM 标记的格式必须是 "a"。',
  'The pattern for day in month must be "F".' => '代表 day in month 的格式必须是 "F"。',
  'The pattern for day in year must be "D", "DD" or "DDD".' => '代表 day in year 的格式必须是 "D", "DD" 或 "DDD"。',
  'The pattern for day of the month must be "d" or "dd".' => '代表 day of the month 的格式必须是 "d" 或 "dd"。',
  'The pattern for era must be "G", "GG", "GGG", "GGGG" or "GGGGG".' => '代表年代的格式必须是 "G", "GG", "GGG", "GGGG" 或 "GGGGG"。',
  'The pattern for hour in AM/PM must be "K" or "KK".' => '代表时(AM/PM格式)的格式必须是 "K" 或 "KK"。',
  'The pattern for hour in day must be "k" or "kk".' => '代表该天第几小时的格式必须是 "k" 或 "kk"。',
  'The pattern for minutes must be "m" or "mm".' => '代表分的格式必须是 "m" 或 "mm"。',
  'The pattern for seconds must be "s" or "ss".' => '代表秒的格式必须是 "s" 或 "ss"。',
  'The pattern for time zone must be "z" or "v".' => '代表时区的格式必须是 "z" 或 "v"。',
  'The pattern for week in month must be "W".' => '代表 week in month 的格式必须是 "W"。',
  'The pattern for week in year must be "w".' => '代表 week in year 的格式必须是 "w"。',
  'The queue is empty.' => '队列状态为空。',
  'The relation "{relation}" in active record class "{class}" is not specified correctly: the join table "{joinTable}" given in the foreign key cannot be found in the database.' => 'active record class "{class}" 中的关联 "{relation}" 未被正确指明: 数据库中无法找到 foreign key 中所给的 join table "{joinTable}"。',
  'The relation "{relation}" in active record class "{class}" is specified with an incomplete foreign key. The foreign key must consist of columns referencing both joining tables.' => 'active record class "{class}" 中的关联 "{relation}" 有一个不完整的 foreign key. foreign key 必须是参照 joining tables 中的栏位所构成。',
  'The relation "{relation}" in active record class "{class}" is specified with an invalid foreign key. The format of the foreign key must be "joinTable(fk1,fk2,...)".' => 'active record class "{class}" 中的关联 "{relation}" 有一个无效的 foreign key. foreign key 的格式必须是 "joinTable(fk1,fk2,...)"。',
  'The stack is empty.' => '堆栈状态为空。',
  'The system is unable to find the requested action "{action}".' => '系统无法找到请求的 "{action}" 动作。',
  'The system view path "{path}" is not a valid directory.' => '系统 view 路径 "{path}" 不是一个有效的目录。',
  'The table "{table}" for active record class "{class}" cannot be found in the database.' => '数据库中无法找到 active record class "{class}" 对应的 table "{table}"。',
  'The verification code is incorrect.' => '验证码不正确。',
  'The view path "{path}" is not a valid directory.' => 'view 路径 "{path}" 不是一个有效的目录。',
  'Theme directory "{directory}" does not exist.' => 'Theme 目录 "{directory}" 不存在。',
  'This content requires the <a href="http://www.adobe.com/go/getflash/">Adobe Flash Player</a>.' => '内容需有 <a href="http://www.adobe.com/go/getflash/">Adobe Flash Player</a>。',
  'Unable to add an item whose name is the same as an existing item.' => '无法新增与已存在项目名称相同的新项目。',
  'Unable to change the item name. The name "{name}" is already used by another item.' => '无法变更项目名称. 名称 "{name}" 已被其它项目使用。',
  'Unable to create application state file "{file}". Make sure the directory containing the file exists and is writable by the Web server process.' => '无法产生应用程序状态文件 "{file}". 请确认存放此文件的目录存在并且允许 Web server process 写入。',
  'Unable to lock file "{file}" for reading.' => '无法锁定文件 "{file}" 进行读取。',
  'Unable to lock file "{file}" for writing.' => '无法锁定文件 "{file}" 进行写入。',
  'Unable to read file "{file}".' => '无法读取文件 "{file}"。',
  'Unable to replay the action "{object}.{method}". The method does not exist.' => '无法再次重演 "{object}.{method}" 动作. 这个方法不存在。',
  'Unable to write file "{file}".' => '无法写入文件 "{file}"。',
  'Unknown authorization item "{name}".' => '未知的授权项目 "{name}"。',
  'Unrecognized locale "{locale}".' => '无法辨识的地区设定 "{locale}"。',
  'View file "{file}" does not exist.' => '名为 "{file}" 的 View 档不存在。',
  'Yii application can only be created once.' => 'Yii 应用程序只能被产生一次。',
  'You are not authorized to perform this action.' => '您未被授权执行这个动作',
  'Your request is not valid.' => '您的请求无效',
  '{attribute} "{value}" has already been taken.' => '{attribute} "{value}" 已被取用。',
  '{attribute} cannot be blank.' => '{attribute} 不可为空白。',
  '{attribute} is invalid.' => '{attribute} 无效。',
  '{attribute} is not a valid URL.' => '{attribute} 不是有效的 URL。',
  '{attribute} is not a valid email address.' => '{attribute} 不是有效的电子邮件地址。',
  '{attribute} is not in the list.' => '{attribute} 不在列表之中。',
  '{attribute} is of the wrong length (should be {length} characters).' => '{attribute} 长度错误 (应为 {length} 字符串)。',
  '{attribute} is too big (maximum is {max}).' => '{attribute} 数值太大 (最大值为 {max})。',
  '{attribute} is too long (maximum is {max} characters).' => '{attribute} 太长 (最大值为 {max} 字符串)。',
  '{attribute} is too short (minimum is {min} characters).' => '{attribute} 太短 (最小值为 {min} 字符串)。',
  '{attribute} is too small (minimum is {min}).' => '{attribute} 数值太小 (最小值为 {min})。',
  '{attribute} must be a number.' => '{attribute} 必须为数字。',
  '{attribute} must be an integer.' => '{attribute} 必须为整数。',
  '{attribute} must be repeated exactly.' => '{attribute} 必须被重复。',
  '{attribute} must be {type}.' => '{attribute} 必须为 {type}。',
  '{className} does not support add() functionality.' => '{className} 不支持 add() 功能。',
  '{className} does not support delete() functionality.' => '{className} 不支持 delete() 功能。',
  '{className} does not support get() functionality.' => '{className} 不支持 get() 功能。',
  '{className} does not support set() functionality.' => '{className} 不支持 set() 功能。',
  '{class} does not have relation "{name}".' => '{class} 中没有名为 "{name}" 的关联。',
  '{class} does not support fetching all table names.' => '{class} 不支持撷取所有 table 名称。',
  '{class} has an invalid validation rule. The rule must specify attributes to be validated and the validator name.' => '{class} 有一个无效的确认规则. 规则必须指明要被确认的属性以及确认器名称。',
  '{class} must specify "model" and "attribute" or "name" property values.' => '{class} 必须给定 "model" 与 "attribute" 或 "name" 属性值。',
  '{class}.allowAutoLogin must be set true in order to use cookie-based authentication.' => '{class}.allowAutoLogin 必须设为 true 才能使用 cookie-based 认证。',
  '{class}::authenticate() must be implemented.' => '{class}::authenticate() 必须被实现。',
  '{controller} cannot find the requested view "{view}".' => '{controller} 无法找到请求的视图 "{view}"。',
  '{controller} contains improperly nested widget tags in its view "{view}". A {widget} widget does not have an endWidget() call.' => '{controller} 在它的 view "{view}" 中含有未被适当巢状套叠的 widget 标签. {widget} widget 中没有呼叫 endWidget()。',
  '{controller} has an extra endWidget({id}) call in its view.' => '{controller} 在它的视图中有一个额外的 endWidget({id}) 呼叫。',
  '{widget} cannot find the view "{view}".' => '{widget} 无法找到这个视图 "{view}"。',
);

zii.php


/**
 * Message translations.
 *
 * This file is automatically generated by 'yiic message' command.
 * It contains the localizable messages extracted from source code.
 * You may modify this file by translating the extracted messages.
 *
 * Each array element represents the translation (value) of a message (key).
 * If the value is empty, the message is considered as not translated.
 * Messages that no longer need translation will have their translations
 * enclosed between a pair of '@@' marks.
 *
 * NOTE, this file must be saved in UTF-8 encoding.
 *
 * @version $Id: $
 */
return array (
  'Home' => '首页',
  'The button type "{type}" is not supported.' => '按钮类型 "{type}" 不支持。',
  'Are you sure you want to delete this item?' => '确定要删除这条数据吗?',
  'Delete' => '删除',
  'Displaying {start}-{end} of {count} result(s).' => '第 {start}-{end} 条, 共 {count} 条。',
  'Either "name" or "value" must be specified for CDataColumn.' => 'CDataColumn 必须指定 "name" 或 "value" 至少一项。',
  'No results found.' => '没有找到数据。',
  'Not set' => '未设置',
  'Please specify the "attributes" property.' => '请指定 "attributes" 属性。',
  'Please specify the "data" property.' => '请指定 "data" 属性。',
  'Sort by: ' => '排序: ',
  'The "dataProvider" property cannot be empty.' => '"dataProvider" 属性不能为空。',
  'The attribute must be specified in the format of "Name:Type:Label", where "Type" and "Label" are optional.' => '属性格式 "Name:Type:Label", "Type" 和 "Label" 为可选项。',
  'The column must be specified in the format of "Name:Type:Label", where "Type" and "Label" are optional.' => '栏位格式 "Name:Type:Label", "Type" 和 "Label" 为可选项。',
  'The property "itemView" cannot be empty.' => '必须指定 "itemView" 属性。',
  'Total {count} result(s).' => '共 {count} 条。',
  'Update' => '更新',
  'View' => '查看',
  '{class} must specify "model" and "attribute" or "name" property values.' => '{class} 必须给定 "model" 与 "attribute" 或 "name" 属性值。',
);
发表在 常见问题解答 | 留下评论

Yii session_save_path 路径设置为相对路径的问题。

在写Yii的代码时(本地windows开发环境下)。Yii升级到最新版本在配置文件中将session_save_path设置成了相对路径 protected/runtime/session

记得在Yii老版本中是没有问题的。也不记得是哪一次升级了框架,就发现怎么也登录不了(而且上线的网站上也登录不了,最后找出新更新的代码把其中包含的session_regenerate_id();去掉了,也就解决了。当时也没管。服务器上的框架也一直没更新)

最近检查发现session文件虽然写入了到了相对目录中,但是session文件都是空的,进一步测试,去掉配置文件中savePath的设置,或者是savePath设置为绝对路径时。一切正常。

这两天有空再次想起这次session_save_path的问题。就又分析了一些。代码如下

test.php

//session_save_path('D:/amp/www/yulutx');
session_save_path('./');
session_start();
if($_SESSION['t']){
	var_dump('time:',$_SESSION['t']);
	$_SESSION['t'] = array();
} else {
	//session_regenerate_id();
	$_SESSION['t'] = date('Y-m-d H:i:s',time());
}

1.session_sva_path 相对路径,无session_regenerate_id();正常
2.session_sva_path 相对路径,有session_regenerate_id();错误
3.session_sva_path 绝对路径,无session_regenerate_id();正常
4.session_sva_path 绝对路径,有session_regenerate_id();正常

以上测试在linux环境下,结果是一样的。

所以在设置session_save_path时最好是设置为绝对路径

发表在 常见问题解答 | 2 条评论

自己做了一个权限分配,欢迎大家前来指教

首先是数据库结构:

CREATE TABLE IF NOT EXISTS `admin_role` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`update_time` int(10) unsigned NOT NULL default '0',
`status` tinyint(1) unsigned NOT NULL default '1',
PRIMARY KEY (`id`),
KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `admin_role_child` (
`role_id` int(10) unsigned NOT NULL,
`item_id` int(10) unsigned NOT NULL,
KEY `item_id` (`item_id`),
KEY `role_id` (`role_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `admin_role_item` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(255) NOT NULL,
`parent_id` int(10) unsigned NOT NULL,
`description` text,
`update_time` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `name` (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

解释一下数据库:
admin_role是角色表,update_time字段是用来做Query Cache的,可要可不要
admin_role_child是权限分配表,只用来保存相应的role拥有的权限
admin_role_item是权限的具体信息,update_time字段也是用来做Query Cache的,可要可不要
然后再说说权限的判断方式:
首先,在数据库保存的权限信息为这种格式:controller/action,就像YII的url route一样,但是他有一种简便的写法,如果要给那个角色某个controller的所有权限,就只要这样写:controller/*
然后,写一个class,扩展自CApplicationComponent或者CAuthManager,无论扩展自那个class,对我这个影响都不大,如果你需要更多的yii原生的class支持,你可以优先考虑CAuthManager。
然后,我的AuthManager里面只有一个方法checkAccess,方法的参数参照CAuthManager的checkAccess,因为要方便CWebUser的调用,代码如下:

* @param array $itemName 需要验证权限的controller id and action id
* @param mixed $userId 需要验证权限的user id
* @param array $params 验证权限附带的参数
* @return boolean 验证结果
*/
public function checkAccess($itemName, $userId, $params=array ( ))
{
$criteria = new CDbCriteria(array('select'=>'is_supper', 'condition'=>'id = :userId', 'params'=>array(':userId'=>$userId)));
$user = Admin::model()->find($criteria);
if ($user->is_supper == 1) return true;
// 获取controller and action
$itemName = explode('/', strtolower($itemName));
$controller = $itemName[0];
$action = $itemName[1];
// 获取会员角色组
$role = AdminRole::model()->getByUser($userId);
Dumper::dump($role->items);Yii::app()->end();
if ($role !== null) foreach ($role->items as $item)
{
// 获取会员角色组权限
$item = explode('/', strtolower($item->name));
// 如果拥有当前控制器权限
if ($item[0] === $controller)
{
// 如果拥有所有权限
if ($item[1] === '*') return true;
// 如果拥有指定权限
else if ($item[1] === $action) return true;
}
}
return false;
}

上面的代码注释应该已经足够大家理解了吧,如果有不理解的,欢迎大家来群讨论!
忘记给大家介绍用法了,只要在要验证的时候写句话就行了,Yii::app()->user->checkAccess(这里写要判断的权限);

发表在 技术文章 | 6 条评论

关于YII Cfilters简单的用法

这几天一直在研究Rights,发现他的loginRequired判断只要在allowedActions定义action就行了,感觉很不错,于是开始了探索。
一路的找下去,发现,他的自动loginRequired是基于filters的,于是就自己写了一个简单的loginRequire filter。
先贴代码:

// 定义filters
public function filterLoginRequired($filterChain)
{
$actions = $this->loginRequiredActions();
if (in_array($filterChain->action->id, $actions))
if (Yii::app()->user->isGuest)
Yii::app()->user->loginRequired();
$filterChain->run();
}

// 调用filters
public function filters()
{
return array('LoginRequired');
}

//定义需要过滤的action
public function loginRequiredActions()
{
return array('index', 'test');
}

下面就来解释一下上面代码的运行流程
首先在Controller里面定义filters的处理,获取需要过滤的action
然后判断CFilterChain中的action是否存在过滤数组中,如果存在数组,则判断用户是否已经登陆,如果没有登陆,则跳转至登陆页面,否则正常执行action
如果看不明白的,欢迎来群交流,我是 请叫我纠结(253176704)。

发表在 技术文章 | 一条评论

yii程序目录布局之行为绑定实例

语录天下行为程序目录结构图

+components
          +blls // 放置业务逻辑的目录,主要处理简单的数据库表操作,注意这里没有放在model里面
                        BllUser.php // 用户表数据逻辑操作类
                         ………………
           +behaviors // 供绑定的行为目录
                         BllBehavior.php // 逻辑类行为,这里定义所有逻辑类所有的调用方式,其实就是实例化这些逻辑类对象

接下来。就是在控制器父类(components/Controller.php),model父类(models/BaseFormModel.php)等等其他需要调用行为的地方绑到BllBehavior或者是其其他行为。这样就可以非常方便的调用数据逻辑操作类了。

部分代码

行为(BllBehavior.php)
public function getBUser()
{
         if($this->_BllUser==null)
                $this->_BllUser=new BllUser;
        return $this->_BllUser;
}

控制器(SiteController.php)

调用BllUser.php对象的方式
$this->getBUser()

模型(RegForm.php)

调用BllUser.php对象的方式
$this->getBUser()

语录天下的行为绑定的就写到这里了。下次再写一点

发表在 技术文章 | 一条评论

关于Yii的assets目录的疑问

雪落无声-Terry
yii的静态文件发布机制,我一直不是很明白。
ning
assets的作用是方便模块化,插件化的,一般来说出于安全原因不允许通过url访问protected下面的文件,但是我们又希望将module单独出来,所以需要使用发布,即将一个目录下的文件复制一份到assets下面方便通过url访问

雪落无声-Terry
默认的css,js等,是不是调用CHtml组件的时候,自动发布过去的?
ning
是的

雪落无声-Terry
但是如果我想把应用的东西整合到一起呢。如果有更新,它应该是不会自动发布吧。
lychee
需要你清空assets目录

雪落无声-Terry
嗯。所以,我想,还是单独用一个静态目录来放静态文件吧。还能方便的做cdn
雪落无声-Terry
但是它相关组件的静态文件,还是会发布出来。
雪落无声-Terry
不过基本上也就只有后台用户能使用这些静态文件。
ning
对于不用模块化的文件,还是可以在目录下建立images,css,js,uploads文件夹的

发表在 常见问题解答 | 标签为 | 留下评论

让Yii的数据库迁移脚本同时支持mysql与sqlite以及外键

以Yii的权限表为例
auth_item

class m110307_150754_auth_item_table extends CDbMigration {

    public function up() {
        $this->createTable('auth_item',array(
            'name'=>'varchar(64) not null',
            'type'=>'integer not null',
            'description'=>'text',
            'bizrule'=>'text',
            'data'=>'text',
            'primary key(name)',
        ));
    }

    public function down() {
        $this->dropTable('auth_item');
    }

}

auth_item_child

class m110307_150817_auth_item_child_table extends CDbMigration {

    public function up() {
        $this->createTable('auth_item_child',array(
            'parent'=>'varchar(64) not null',
            'child'=>'varchar(64) not null',
            'PRIMARY KEY(parent,child)',
            'FOREIGN KEY(parent) REFERENCES auth_item(name) ON UPDATE CASCADE ON DELETE CASCADE',
            'FOREIGN KEY(child) REFERENCES auth_item(name) ON UPDATE CASCADE ON DELETE CASCADE',
        ));
    }

    public function down() {
        $this->dropTable('auth_item_child');
    }

}

auth_assignment

class m110307_150856_auth_assignment_table extends CDbMigration {

    public function up() {
        $this->createTable('auth_assignment',array(
            'itemname'=>'varchar(64) not null',
            'userid'=>'varchar(64) not null',
            'bizrule'=>'varchar(64) not null',
            'data'=>'varchar(64) not null',
            'primary key (itemname,userid)',
            'FOREIGN KEY(itemname) REFERENCES auth_item(name) ON UPDATE CASCADE ON DELETE CASCADE',
        ));
    }

    public function down() {
        $this->dropTable('auth_assignment');
    }

}
发表在 技术文章 | 标签为 | 留下评论

Yii框架无法运行命令行常见错误解决办法

(1)新建webapp时,出现找不到“php.exe”的错误

解决办法:

出现这个错误很大的原因是用户使用了打包的绿色的php的安装环境,

所以用户可以打开

yiic.bat 文件编辑这句话:将PHP_COMMAND 的值改成你的安装环境中的php.exe的绝对路径
if "%PHP_COMMAND%" == "" set PHP_COMMAND=php.exe

(2)执行 webroot(webapp安装根目录)\protected\yiic shell时,出现 找不到“index.php”

解决办法:

将执行语句改成:webroot(webapp安装根目录)\protected\yiic shell webroot(webapp安装根目录)\index.php

(3)创建model时:出现 找不到pdo错误

解决办法:

出现这个错误的原因也是用户使用了打包的绿色的php的安装环境,这时候将你的安装环境中的php.ini 拷贝到C:\Windows目录中,然后编辑以下语句:
extension_dir = "..\..\php-5.2.9-2-Win32\ext"
将ext的路径改成你的安装环境中对应目录的绝对路径。

(4)注意一个问题:yii应用系统的数据表似乎不支持 带空格的字段名。。例如:字段member id 需把空格去掉 改成memberid
原文地址:http://blog.csdn.net/love_c2004/archive/2009/08/22/4473847.aspx

发表在 常见问题解答 | 留下评论

如何使用Active Record进行关联查询

class News extends CActiveRecord
{
	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
            'type' => array(self::BELONGS_TO, 'NewsType', 'type_id')
		);
	}
}

// 在News设置了关联NewsType;
$news=News::model()->findByPk(77);

// 获取新闻的类别(type): 此处将执行一个关联查询。惰式加载
$type=$post->type;

// 如果调用N个新闻查询时,例如
$dataProvider=new CActiveDataProvider('News'); 

// 或者
$data = News::model()->findAll();

// 懒惰式就不高效,
// 这时应该使用如下方式进行预加载
$dataProvider=new CActiveDataProvider('News',
array('criteria' => new CDbCriteria(array('with' => array('type')));
// 或者
$data=News::model()->with('type')->findAll();
发表在 技术文章 | 留下评论

使用jquery ui autocomplete实现可编辑的下拉菜单

先说用途:
主要在原来的autocomplete上修改,鼠标点击时直接弹出下拉层,选择后再次点击,仍然会再次弹出所有的选项。方便选择单位、部门等选项不多的情况。

再上代码:

 $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
            'source' => array_values(CHtml::listData(Unit::model()->findAll(), 'id', 'title')),
            'options' => array(
                'delay' => 0,
                'minLength' => 0,
            ),
            'model' => $model,
            'attribute' => 'unit_id',
            'htmlOptions' => array(
                'style' => 'height:20px;'
            ),
        ));
        Yii::app()->clientScript->registerScript('unit_auto_show', "
$('#" . CHtml::activeId($model, 'unit_id') . "').bind('focus click',function(){
   $(this).autocomplete('search','');
});
    ");

然后上图:

参考地址:
http://jqueryui.com/demos/autocomplete/#combobox
http://www.yiiframework.com/doc/api/1.1/CJuiAutoComplete

发表在 技术文章 | 标签为 , , , , , , | 留下评论