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的更多相关文章

  1. Deal with relational data using libFM with blocks

    原文:https://thierrysilbermann.wordpress.com/2015/09/17/deal-with-relational-data-using-libfm-with-blo ...

  2. 《Using Databases with Python》Week3 Data Models and Relational SQL 课堂笔记

    Coursera课程<Using Databases with Python> 密歇根大学 Week3 Data Models and Relational SQL 15.4 Design ...

  3. Yii2中mongodb使用ActiveRecord的数据操作

    概况  Yii2 一个高效安全的高性能PHP框架.mongodb 一个高性能分布式文档存储NOSQL数据库. 关于mongodb与mysql的优缺点,应该都了解过. mysql传统关系数据库,安全稳定 ...

  4. ExtJS4笔记 Data

    The data package is what loads and saves all of the data in your application and consists of 41 clas ...

  5. 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 ...

  6. 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 ...

  7. Coursera, Big Data 2, Modeling and Management Systems (week 1/2/3)

    Introduction to data management 整个coures 2 是讲data management and storage 的,主要内容就是分布式文件系统,HDFS, Redis ...

  8. [Windows Azure] Data Management and Business Analytics

    http://www.windowsazure.com/en-us/develop/net/fundamentals/cloud-storage/ Managing and analyzing dat ...

  9. 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 ...

随机推荐

  1. 6.JBoss5.x6.x 反序列化漏洞(CVE-2017-12149)复现

    2017 年 9 月 14 日,国家信息安全漏洞共享平台( CNVD )收录了 JBOSS Application Server 反序列化命令执行漏洞( CNVD-2017-33724,对应 CVE- ...

  2. 1.4 DVWA亲测XSS漏洞

    首先需要有配置好的DVWA环境,像下图这样   其中: XSS (DOM) :  DOM型XSS漏洞 XSS (Reflected) : 反射性XSS漏洞  XSS (Stored) :  存储型XS ...

  3. Mac效率工具推荐

    1.Homebrew 命令行安装神器 https://brew.sh/index_zh-cn.html 2.Alfred 类似spotlight,功能更强大 https://www.alfredapp ...

  4. C++开源库(一) ----log4cpp详解

    我们在写程序的时候通常会希望将一些信息记录下来,方便我们进行日后的一些信息跟踪,错误排查等等.比如:我们在进行数据库操作的时候,我们通常希望知道现在是程序的哪一部分进行了数据库的操作,所以我们会记录下 ...

  5. 乐字节Java8核心特性之Optional类

    大家好啊,上次小乐给大家介绍了Java8最最重要的一个特性——Stream流,点击可以回顾哦. Optional<T>类(java.util.Optional)是一个容器类,代表一个值存在 ...

  6. 洛谷P2184 贪婪大陆

    题目背景 面对蚂蚁们的疯狂进攻,小FF的\(Tower\) \(defence\)宣告失败--人类被蚂蚁们逼到了\(Greed\) \(Island\)上的一个海湾.现在,小FF的后方是一望无际的大海 ...

  7. VC添加全局热键的方法

    VC添加全局热键的方法 这个方法靠谱 http://blog.csdn.net/lujianfeiccie2009/article/details/7498704 VC添加全局热键的方法 标签: bu ...

  8. 通过用axios发送请求,全局拦截请求,获取到错误弄明白promise对象

    axios.interceptors.response.use(function (response) { // 对响应数据做点什么 return response; }, function (err ...

  9. P2308 添加括号(区间DP)

    题目背景 给定一个正整数序列a(1),a(2),...,a(n),(1<=n<=20) 不改变序列中每个元素在序列中的位置,把它们相加,并用括号记每次加法所得的和,称为中间和. 例如: 给 ...

  10. Selenium WebDriver原理(二):Selenium是如何操纵浏览器的?

    前言 上一篇文章<selenium webdriver 是怎么运行的>用了一个简单的例子--搭出租车,形象地讲解selenium webdriver 是如何运行的,而这一篇文章可以理解为深 ...