• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP CModel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中CModel的典型用法代码示例。如果您正苦于以下问题:PHP CModel类的具体用法?PHP CModel怎么用?PHP CModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了CModel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: clientValidateAttribute

	/**
	 * Returns the JavaScript needed for performing client-side validation.
	 * @param CModel $object the data object being validated
	 * @param string $attribute the name of the attribute to be validated.
	 * @return string the client-side validation script.
	 * @see CActiveForm::enableClientValidation
	 * @since 1.1.7
	 */
	public function clientValidateAttribute($object,$attribute)
	{
		if($this->pattern===null)
			throw new CException(Yii::t('yii','The "pattern" property must be specified with a valid regular expression.'));

		$message=$this->message!==null ? $this->message : Yii::t('yii','{attribute} is invalid.');
		$message=strtr($message, array(
			'{attribute}'=>$object->getAttributeLabel($attribute),
		));

		$pattern=$this->pattern;
		$pattern=preg_replace('/\\\\x\{?([0-9a-fA-F]+)\}?/', '\u$1', $pattern);
		$delim=substr($pattern, 0, 1);
		$endpos=strrpos($pattern, $delim, 1);
		$flag=substr($pattern, $endpos + 1);
		if ($delim!=='/')
			$pattern='/' . str_replace('/', '\\/', substr($pattern, 1, $endpos - 1)) . '/';
		else
			$pattern = substr($pattern, 0, $endpos + 1);
		if (!empty($flag))
			$pattern .= preg_replace('/[^igm]/', '', $flag);

		return "
if(".($this->allowEmpty ? "$.trim(value)!='' && " : '').($this->not ? '' : '!')."value.match($pattern)) {
	messages.push(".CJSON::encode($message).");
}
";
	}
开发者ID:alsvader,项目名称:hackbanero,代码行数:36,代码来源:CRegularExpressionValidator.php


示例2: clientValidateAttribute

	/**
	 * Returns the JavaScript needed for performing client-side validation.
	 * @param CModel $object the data object being validated
	 * @param string $attribute the name of the attribute to be validated.
	 * @return string the client-side validation script.
	 * @see CActiveForm::enableClientValidation
	 * @since 1.1.7
	 */
	public function clientValidateAttribute($object,$attribute)
	{
		$message=$this->message;
		if($this->requiredValue!==null)
		{
			if($message===null)
				$message=Yii::t('yii','{attribute} must be {value}.');
			$message=strtr($message, array(
				'{value}'=>$this->requiredValue,
				'{attribute}'=>$object->getAttributeLabel($attribute),
			));
			return "
if(value!=" . CJSON::encode($this->requiredValue) . ") {
	messages.push(".CJSON::encode($message).");
}
";
		}
		else
		{
			if($message===null)
				$message=Yii::t('yii','{attribute} cannot be blank.');
			$message=strtr($message, array(
				'{attribute}'=>$object->getAttributeLabel($attribute),
			));
			return "
if($.trim(value)=='') {
	messages.push(".CJSON::encode($message).");
}
";
		}
	}
开发者ID:alsvader,项目名称:hackbanero,代码行数:39,代码来源:CRequiredValidator.php


示例3: validateAttribute

 /**
  * Validates a single attribute.
  * 
  * @param CModel $object the data object being validated
  * @param string $attribute the name of the attribute to be validated.
  */
 protected function validateAttribute($object, $attribute)
 {
     $value = $object->{$attribute};
     if ($this->isEmpty($value)) {
         if ($this->allowEmpty) {
             return;
         } else {
             $arrValidators = $object->getValidators($attribute);
             foreach ($arrValidators as $objValidator) {
                 // do not duplicate error message if attribute is already required
                 if ($objValidator instanceof CRequiredValidator) {
                     return;
                 }
             }
             $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} cannot be blank.');
             $this->addError($object, $attribute, $message);
         }
     } else {
         $return = $this->validateIBAN($value);
         if (true !== $return) {
             $message = $this->message !== null ? $this->message : $this->getErrorMessage($return, $value);
             $this->addError($object, $attribute, $message);
         }
     }
 }
开发者ID:Diakonrus,项目名称:fastweb-yii,代码行数:31,代码来源:EIBANValidator.php


示例4: renderInput

 public function renderInput(CModel $model, $attribute, array $htmlOptions = array())
 {
     $action = new Actions();
     $action->setAttributes($model->getAttributes(), false);
     $defaultOptions = array('id' => $this->resolveId($attribute));
     $htmlOptions = X2Html::mergeHtmlOptions($defaultOptions, $htmlOptions);
     return preg_replace('/Actions(\\[[^\\]]*\\])/', get_class($this->formModel) . '$1', $action->renderInput($attribute, $htmlOptions));
 }
开发者ID:shuvro35,项目名称:X2CRM,代码行数:8,代码来源:ActionActiveFormBase.php


示例5: fieldClass

 /**
  * Returns input container class for any given attribute, depending on validation conditions.
  * @param CModel $model the data model
  * @param string $attribute the attribute name
  */
 public function fieldClass($model, $attribute)
 {
     $class = 'control-group';
     if ($model->getError($attribute)) {
         $class .= ' error';
     }
     return $class;
 }
开发者ID:rzamarripa,项目名称:masoftproyectos,代码行数:13,代码来源:BActiveForm.php


示例6: errorModelSummery

 /**
  * get error info from model
  * 
  * @param CModel $model
  * @return string
  * @see CModel
  */
 public static function errorModelSummery($model, $attribute = null)
 {
     if (is_null($attribute)) {
         return self::errorSummery($model->getErrors());
     } else {
         $aryError = $model->getError($attribute, false);
         return empty($aryError) ? '' : self::errorSummery(array($aryError));
     }
 }
开发者ID:erdincay,项目名称:WIIBOX,代码行数:16,代码来源:CHtml.php


示例7: getErrorMessage

 /**
  * Returns the validation error message.
  * @param CModel $object the data object being validated.
  * @param string $attribute the name of the attribute to be validated.
  * @return string the message.
  */
 public function getErrorMessage($object, $attribute)
 {
     if (isset($this->message)) {
         $message = $this->message;
     } else {
         $message = Yii::t('validator', 'This value must be repeated exactly.');
     }
     return strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute)));
 }
开发者ID:nordsoftware,项目名称:yii-parsley,代码行数:15,代码来源:ParsleyCompareValidator.php


示例8: validateAttribute

 /**
  * Validates the attribute of the object.
  * @param CModel $object the object being validated
  * @param string $attribute the attribute being validated
  */
 protected function validateAttribute($object, $attribute)
 {
     if ($this->setOnEmpty && !$this->isEmpty($object->{$attribute})) {
         return;
     }
     if (!$object->hasAttribute($this->translitAttribute)) {
         throw new CException(Yii::t('yiiext', '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.', array('{class}' => get_class($object), '{column}' => $this->translitAttribute)));
     }
     $object->{$attribute} = self::latin($object->getAttribute($this->translitAttribute));
 }
开发者ID:kosenka,项目名称:yboard,代码行数:15,代码来源:Translit.php


示例9: validateAttribute

 /**
  * Validates the attribute of the object.
  * If there is any error, the error message is added to the object.
  * @param CModel $object the object being validated
  * @param string $attribute the attribute being validated
  */
 protected function validateAttribute($object, $attribute)
 {
     $value = $object->{$attribute};
     if ($this->allowEmpty && $this->isEmpty($value)) {
         return;
     }
     if ($this->compareValue !== null) {
         $compareTo = $compareValue = $this->compareValue;
     } else {
         $compareAttribute = $this->compareAttribute === null ? $attribute . '_repeat' : $this->compareAttribute;
         $compareValue = $object->{$compareAttribute};
         $compareTo = $object->getAttributeLabel($compareAttribute);
     }
     switch ($this->operator) {
         case '=':
         case '==':
             if ($this->strict && $value !== $compareValue || !$this->strict && $value != $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be repeated exactly.');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo));
             }
             break;
         case '!=':
             if ($this->strict && $value === $compareValue || !$this->strict && $value == $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must not be equal to "{compareValue}".');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo, '{compareValue}' => $compareValue));
             }
             break;
         case '>':
             if ($value <= $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be greater than "{compareValue}".');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo, '{compareValue}' => $compareValue));
             }
             break;
         case '>=':
             if ($value < $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be greater than or equal to "{compareValue}".');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo, '{compareValue}' => $compareValue));
             }
             break;
         case '<':
             if ($value >= $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be less than "{compareValue}".');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo, '{compareValue}' => $compareValue));
             }
             break;
         case '<=':
             if ($value > $compareValue) {
                 $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be less than or equal to "{compareValue}".');
                 $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareTo, '{compareValue}' => $compareValue));
             }
             break;
         default:
             throw new CException(Yii::t('yii', 'Invalid operator "{operator}".', array('{operator}' => $this->operator)));
     }
 }
开发者ID:Jride,项目名称:accounting-thaiconnections,代码行数:61,代码来源:CCompareValidator.php


示例10: validateValue

 protected function validateValue(CModel $object, $value, $attribute)
 {
     // exception added for case where validator is added to AmorphousModel
     if (!$object instanceof X2Model) {
         return;
     }
     $field = $object->getField($attribute);
     $linkType = $field->linkType;
     $model = X2Model::model($linkType);
     if (!$model || !$model->findByPk($value)) {
         $this->error(Yii::t('admin', 'Invalid {fieldName}', array('{fieldName}' => $field->attributeLabel)));
         return false;
     }
 }
开发者ID:dsyman2,项目名称:X2CRM,代码行数:14,代码来源:X2ModelForeignKeyValidator.php


示例11: getErrorMessage

 /**
  * Returns the validation error message.
  * @param CModel $object the data object being validated.
  * @param string $attribute the name of the attribute to be validated.
  * @return string the message.
  */
 public function getErrorMessage($object, $attribute)
 {
     if (isset($this->message)) {
         $message = $this->message;
     } elseif (isset($this->min, $this->max)) {
         $message = Yii::t('validator', 'You must select between {min} and {max} choices.');
     } elseif (isset($this->min)) {
         $message = Yii::t('validator', 'You must select at least {min} choices.');
     } elseif (isset($this->max)) {
         $message = Yii::t('validator', 'You cannot have more than {max} choices selected.');
     } else {
         $message = Yii::t('validator', 'Invalid amount of choices selected.');
     }
     return strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute), '{min}' => $this->min, '{max}' => $this->max));
 }
开发者ID:nordsoftware,项目名称:yii-parsley,代码行数:21,代码来源:ParsleyCheckboxValidator.php


示例12: beginControlGroup

 public function beginControlGroup(CModel $model, $attributes, $htmlOptions = array())
 {
     if (!isset($htmlOptions['class'])) {
         $htmlOptions['class'] = 'control-group';
     }
     if (!is_array($attributes)) {
         $attributes = explode(',', str_replace(' ', '', $attributes));
     }
     foreach ($attributes as $attr) {
         if ($model->hasErrors($attr)) {
             $htmlOptions['class'] .= ' error';
         }
     }
     return CHtml::tag('div', $htmlOptions, false, false);
 }
开发者ID:jankichaudhari,项目名称:yii-site,代码行数:15,代码来源:AdminForm.php


示例13: Action_index

 public function Action_index()
 {
     // 检测用户是否登录
     if (AdminController::isLogin()) {
         return CResponse::getInstance()->redirect(array('c' => 'admin', 'a' => 'index'));
     }
     if ($_POST) {
         // 获取参数
         $username = $this->Args('username', 'string');
         $password = $this->Args('password', 'string');
         // 检查登陆
         $userCheckStatus = CModel::factory('adminUserModel')->userCheck($username, $password);
         // 检查失败
         if (false == $userCheckStatus['status']) {
             // 登录失败
             $this->assign('userLoginStatus', $userCheckStatus);
         } else {
             // 允许登陆
             $userLoginStatus = CModel::factory('adminUserModel')->userLogin($userCheckStatus);
             if ($userLoginStatus['status'] == false) {
                 $this->assign('userLoginStatus', $userLoginStatus);
             } else {
                 // 登录成功
                 CResponse::getInstance()->redirect($userLoginStatus['urlPram']);
             }
         }
     }
     $this->display();
 }
开发者ID:seiven,项目名称:ACEAdminForMyframework,代码行数:29,代码来源:base.php


示例14: clientValidateAttribute

 /**
  * Returns the JavaScript needed for performing client-side validation.
  * @param CModel $object the data object being validated
  * @param string $attribute the name of the attribute to be validated.
  * @return string the client-side validation script.
  * @see CActiveForm::enableClientValidation
  * @since 1.1.7
  */
 public function clientValidateAttribute($object, $attribute)
 {
     if (!is_array($this->range)) {
         throw new CException(Yii::t('yii', 'The "range" property must be specified with a list of values.'));
     }
     if (($message = $this->message) === null) {
         $message = $this->not ? Yii::t('yii', '{attribute} is in the list.') : Yii::t('yii', '{attribute} is not in the list.');
     }
     $message = strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute)));
     $range = array();
     foreach ($this->range as $value) {
         $range[] = (string) $value;
     }
     $range = CJSON::encode($range);
     return "\nif(" . ($this->allowEmpty ? "\$.trim(value)!='' && " : '') . ($this->not ? "\$.inArray(value, {$range})>=0" : "\$.inArray(value, {$range})<0") . ") {\n\tmessages.push(" . CJSON::encode($message) . ");\n}\n";
 }
开发者ID:nizsheanez,项目名称:blog.ru,代码行数:24,代码来源:CRangeValidator.php


示例15: clientValidateAttribute

 /**
  * Returns the JavaScript needed for performing client-side validation.
  * @param CModel $object the data object being validated
  * @param string $attribute the name of the attribute to be validated.
  * @return string the client-side validation script.
  * @see CActiveForm::enableClientValidation
  * @since 1.1.7
  */
 public function clientValidateAttribute($object, $attribute)
 {
     $message = $this->message;
     if ($this->requiredValue !== null) {
         if ($message === null) {
             $message = Yii::t('yii', '{attribute} phải là {value}.');
         }
         $message = strtr($message, array('{value}' => $this->requiredValue, '{attribute}' => $object->getAttributeLabel($attribute)));
         return "\nif(value!=" . CJSON::encode($this->requiredValue) . ") {\n\tmessages.push(" . CJSON::encode($message) . ");\n}\n";
     } else {
         if ($message === null) {
             $message = Yii::t('yii', '{attribute} không thể trống.');
         }
         $message = strtr($message, array('{attribute}' => $object->getAttributeLabel($attribute)));
         return "\nif(jQuery.trim(value)=='') {\n\tmessages.push(" . CJSON::encode($message) . ");\n}\n";
     }
 }
开发者ID:huydoan95,项目名称:huydoan95.github.hotrosvtdmu,代码行数:25,代码来源:CRequiredValidator.php


示例16: login

 /**
  * 管理员登录
  */
 protected function login()
 {
     $username = $this->input->post('username', true);
     $password = $this->input->post('password', true);
     $this->_user->username = trim($username);
     $this->_user->password = $password;
     $modLogin = CModel::make('admin/loginman_model', 'loginman_model');
     $boolean = $modLogin->authenticate($this->_user);
     return $boolean === true && $modLogin->save();
 }
开发者ID:shreksrg,项目名称:microHR,代码行数:13,代码来源:loginman.php


示例17: validateAttribute

 /**
  * Validates a single attribute.
  *
  * @param CModel $object    the data object being validated
  * @param string $attribute the name of the attribute to be validated.
  */
 protected function validateAttribute($object, $attribute)
 {
     if (!$object->isAttributeDirty($attribute)) {
         return;
     }
     if ($this->model === null) {
         //currently unsupported
         return;
     }
     if ($this->message === null) {
         $this->message = '{attribute} can not be edited because it is already in use';
     }
     if ($this->foreignKey === null) {
         $this->foreignKey = $object->tableName() . '_id';
     }
     if ($this->validateContainedInModel($object->id)) {
         $this->addError($object, $attribute, $this->message);
     }
 }
开发者ID:openeyes,项目名称:openeyes,代码行数:25,代码来源:NotContainedInValidator.php


示例18: getModelElements

 /**
  * Get elements from model.
  * @static
  * @param CModel $model
  * @return array
  */
 public static function getModelElements($model)
 {
     $elements = array();
     $scenario = $model->getScenario();
     foreach ($model->getFormElements() as $name => $element) {
         $on = array();
         if (isset($element['on']) && is_array($element['on'])) {
             $on = $element['on'];
         } else {
             if (isset($element['on'])) {
                 $on = preg_split('/[\\s,]+/', $element['on'], -1, PREG_SPLIT_NO_EMPTY);
             }
         }
         if (empty($on) || in_array($scenario, $on)) {
             unset($element['on']);
             $elements[$name] = $element;
         }
     }
     return $elements;
 }
开发者ID:sinelnikof,项目名称:yiiext,代码行数:26,代码来源:EFormElementCollection.php


示例19: factory

 /**
  * 工厂方法
  */
 public static function factory($modelName = null)
 {
     if (empty($modelName)) {
         return CModel::getInstance();
     }
     if (!isset(self::$modelList[$modelName])) {
         self::$modelList[$modelName] = new $modelName();
         return self::$modelList[$modelName];
     }
     return self::$modelList[$modelName];
 }
开发者ID:seiven,项目名称:ACEAdminForMyframework,代码行数:14,代码来源:CModel.php


示例20: __construct

 public function __construct()
 {
     parent::__construct();
     # CONFIGURE TABLE WITH PREFIX
     //$db_config = Config::get_database();
     //$prefix = $db_config['prefix'] == '' ? '' : $db_config['prefix'];
     $this->table = 'photonews_detail';
     //$prefix . "_photonews_detail";
     $this->news_table = "news";
     //"news_" . date('Y'); //$prefix . "_news_" . date('Y');
     $this->news_rubric = 'news_rubrics';
     //$prefix ."_news_rubrics";
     $this->taq_news = 'tag_news';
     //$prefix ."_tag_news";
     $this->keyword = 'news_keywords';
     //$prefix ."_news_keywords";
     $this->user_table = 'users';
     //$prefix ."_users";
     $this->photo_table = 'photo';
     //$prefix ."_photo";
     $this->photonews_detail = 'photonews_detail';
     //$prefix ."_photonews_detail";
     # END CONFIGURE
     mysql_query("SET time_zone='+07:00';");
 }
开发者ID:cyberorca,项目名称:dfp-api,代码行数:25,代码来源:photonews_model.php



注:本文中的CModel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP CModule类代码示例发布时间:2022-05-23
下一篇:
PHP CMenu类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap