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 ...
随机推荐
- 36.浅谈DLL劫持
最近在搞内网,需要实现免杀后门,大佬推荐了dll劫持,DLL劫持后,能干很多事情,比如杀软对某些厂商的软件是实行白名单的,你干些敏感操作都是不拦截,不提示的.还有留后门,提权等等.本文主要介绍如何检测 ...
- HDU - 5542 The Battle of Chibi(LIS+树状数组优化)
The Battle of Chibi Cao Cao made up a big army and was going to invade the whole South China. Yu Zho ...
- Pillow不支持color emoji font!
我想在MAC下面用pillow把一些文本转换成PNG图片,在转普通文字的时候都没问题,但在遇到emoji字符的时候就搞不定了,代码如下: import loggingimport PIL.Image ...
- 《OD学hadoop》20160903某旅游网项目实战
一.大数据的落地点 1.数据出售 数据商城:以卖数据为公司的核心业务 2. 数据分析 百度统计 友盟 GA IBM analysis 3.搜索引擎 4. 推荐系统 mahout 百分比 5.精准营销 ...
- 清北刷题冲刺 10-31 p.m
数列 #include<iostream> #include<cstdio> using namespace std; long long a,b,ans; void f(lo ...
- NoSuchMethodError idea解决jar包冲突
报NoSuchMethodError(使用spring boot框架idea)一般是jar包冲突 Exception in thread"main" java.lang.NoSuc ...
- CF446B DZY Loves Modification 优先队列
As we know, DZY loves playing games. One day DZY decided to play with a n × m matrix. To be more pre ...
- day16正则表达式作业详解
1.正则表达式练习题 点击查看详细内容 作业的讲解 1.匹配整数或者小数(包括正数和负数) -?\d+.\d+|-?\d+ -?\d+(\.\d+)? 2.匹配年月日日期 格式2018-12-6 #找 ...
- 从select机制谈到epoll机制
目录 为什么要用select机制 等待队列 唤醒操作 什么是select机制 关于fd_set select使用 poll函数 为什么select效率较低 什么是epoll epoll机制实现思路 e ...
- P2308 添加括号(区间DP)
题目背景 给定一个正整数序列a(1),a(2),...,a(n),(1<=n<=20) 不改变序列中每个元素在序列中的位置,把它们相加,并用括号记每次加法所得的和,称为中间和. 例如: 给 ...