Yii2 Working with Relational Data at ActiveDataProvider
Yii2 Working with Relational Data at ActiveDataProvider
namespace common\models; use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Recording; /**
* RecordingSearch represents the model behind the search form about `common\models\Recording`.
*/
class RecordingSearch extends Recording
{
public $integerReg = '/^\s*[+-]?\d+\s*$/'; /**
* @inheritdoc
*/
public function rules()
{
return [
[['book_id'], 'integerAndString'],
];
} public function integerAndString($attribute, $params)
{
if (!preg_match($this->integerReg, $this->$attribute) && !is_string($this->$attribute)) {
$this->addError($attribute, Yii::t('yii', '{attribute} must be an integer or a string.', ['attribute'=>$this->getAttributeLabel($attribute)]));
}
} /**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
// ...... if (empty($this->book_id) || preg_match($this->integerReg, $this->book_id)) {
$query->andFilterWhere(['book_id' => $this->book_id]);
} else {
$query->joinWith('book')->andFilterWhere(['like', Book::tableName().'.name', $this->book_id]);
} // ......
}
}
Yii2 Working with Relational Data at ActiveDataProvider的更多相关文章
- Deal with relational data using libFM with blocks
原文:https://thierrysilbermann.wordpress.com/2015/09/17/deal-with-relational-data-using-libfm-with-blo ...
- 《Using Databases with Python》Week3 Data Models and Relational SQL 课堂笔记
Coursera课程<Using Databases with Python> 密歇根大学 Week3 Data Models and Relational SQL 15.4 Design ...
- Yii2中mongodb使用ActiveRecord的数据操作
概况 Yii2 一个高效安全的高性能PHP框架.mongodb 一个高性能分布式文档存储NOSQL数据库. 关于mongodb与mysql的优缺点,应该都了解过. mysql传统关系数据库,安全稳定 ...
- ExtJS4笔记 Data
The data package is what loads and saves all of the data in your application and consists of 41 clas ...
- MySQL vs. MongoDB: Choosing a Data Management Solution
原文地址:http://www.javacodegeeks.com/2015/07/mysql-vs-mongodb.html 1. Introduction It would be fair to ...
- 100 open source Big Data architecture papers for data professionals
zhuan :https://www.linkedin.com/pulse/100-open-source-big-data-architecture-papers-anil-madan Big Da ...
- Coursera, Big Data 2, Modeling and Management Systems (week 1/2/3)
Introduction to data management 整个coures 2 是讲data management and storage 的,主要内容就是分布式文件系统,HDFS, Redis ...
- [Windows Azure] Data Management and Business Analytics
http://www.windowsazure.com/en-us/develop/net/fundamentals/cloud-storage/ Managing and analyzing dat ...
- Putting Apache Kafka To Use: A Practical Guide to Building a Stream Data Platform-part 1
转自: http://www.confluent.io/blog/stream-data-platform-1/ These days you hear a lot about "strea ...
随机推荐
- c++中字符串的截取:
c++中字符串的截取: string 类提供字符串处理函数,利用这些函数,程序员可以在字符串内查找字符,提取连续字符序列(称为子串),以及在字符串中删除和添加.我们将介绍一些主要函数. 1.函数fin ...
- Thinkphp通过phpqrcode实现网址验证码
第一步: phpqrcode下载第三方扩展包,http://phpqrcode.sourceforge.net/ 第二步: 将扩展包放到/ThinkPHP/Library/Vendor/下的Phpqr ...
- js中top.location.href、parent.location.href用法
window.location.href.location.href是本页面跳转 parent.location.href是上一层页面跳转 top.location.href是最外层的页面跳转 举例说 ...
- Linux ubi子系统原理分析
本文思维导图总纲: 综述 关于ubi子系统,早已有比较正式的介绍,也提供非常形象的介绍ubi子系统ppt 国内的前辈 alloysystem 不辞辛劳为我们提供了部分正式介绍的中文译文,以及找不到原文 ...
- 学习RadonDB源码(一)
1. 可能是开始也可能是结束 RadonDB是国内知名云服务提供商青云开源的一款产品,下面是一段来自官方的介绍: QingCloud RadonDB 是基于 MySQL 研发的新一代分布式关系型数据库 ...
- python的virtualenv环境与使用
1.安装virtualenv 在安装virtualenv之前,我们需要安装至少有一个版本的Python:因为virtualenv是python的一个第三方模块,必须基于python环境才能安装: 如果 ...
- 洛谷P1022 计算器的改良
P1022 计算器的改良 题目背景 NCL是一家专门从事计算器改良与升级的实验室,最近该实验室收到了某公司所委托的一个任务:需要在该公司某型号的计算器上加上解一元一次方程的功能.实验室将这个任务交给了 ...
- 历年NOIP真题总结
前言:最近把历年的NOIP真题肝了一遍(还有3个紫题先咕掉了),主要是到1998年的提高组的题.把题目的做题简要思路搁在这儿,一个是为了考前翻一翻,想想自己的哪些思路要梳理的什么什么的,反正怎么说呢, ...
- web版聊天框
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- C/C++规范学习:
一 关于浮点数: 1.1浮点数是否等于0判断:因为浮点数都有精度,不能拿浮点数直接和0.0f进行比较,而应该采用以下方法: if (f32Data == 0.0f) // 隐含错误的比较 #defin ...