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. SQL Server中通过设置非聚集索引(Non-Clustered index)来达到性能优化的目的

    首先我们一下,在SQL Server 2014 Management Studio中,如何为一张表设置Non-Clustered index 具体可以参考  https://docs.microsof ...

  2. c++中字符串的截取:

    c++中字符串的截取: string 类提供字符串处理函数,利用这些函数,程序员可以在字符串内查找字符,提取连续字符序列(称为子串),以及在字符串中删除和添加.我们将介绍一些主要函数. 1.函数fin ...

  3. Eclipse 整合SpringMybatis,SpringMVC,用Maven管理项目搭建详情

    环境:JDK下载地址 https://pan.baidu.com/s/1UyvEAI-4Ci6TDdVJiYUUiQ 密码:ma51 IDE:eclipse下载地址 https://pan.baidu ...

  4. ubuntu 安装 mysql 5.7 简记

    安装: apt-get install mysql-server 会安装最新版本的 mysql ,安装时会提示输入 root 的密码 进入 mysql: mysql -u root -p 进入后会出现 ...

  5. 洛谷P3092 [USACO13NOV]没有找零No Change

    P3092 [USACO13NOV]没有找零No Change 题目描述 Farmer John is at the market to purchase supplies for his farm. ...

  6. Mybatis插件Plugin

    Mybatis开源Plugin中最熟知的pagehelper,重点made in China 很多人开始用pagehelper时候,肯定很纳闷,以mysql为例,明明没有加limit语句,为什么打印出 ...

  7. EOS多主机多节点环境配置

    本文使用了四台同网段的主机,第一台做为eosio创世用户使用,另外三台做为出块者节点使用,最终实现了EOS多主机多节点的配置.最后EOSIO创世用户不再出块,由选举出来的各个节点轮流出块,下面将介绍具 ...

  8. PAT天梯赛L2-025 分而治之

    题目链接:点击打开链接 分而治之,各个击破是兵家常用的策略之一.在战争中,我们希望首先攻下敌方的部分城市,使其剩余的城市变成孤立无援,然后再分头各个击破.为此参谋部提供了若干打击方案.本题就请你编写程 ...

  9. chromedriver对应chrom版本

    chromedriver版本 支持的Chrome版本 v2.37 v64-66 v2.36 v63-65 v2.35 v62-64 v2.34 v61-63 v2.33 v60-62 v2.32 v5 ...

  10. Kipmi0 占用CPU 100%

    查看当前正在运行的进程发现kipmi0进程占用率达到100% kipmi -% of the CPUs, %/% comes when the machine is idle? A second is ...