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]);
        }

        // ......
    }
}
时间: 2024-10-06 15:23:37

Yii2 Working with Relational Data at ActiveDataProvider的相关文章

DataBaseSystem:Relational Data Structure

本篇内容来自<数据库系统概论(第五版)>(王珊 萨师煊),主要是整理数据库的基本概念,供自己复习查阅. 关系数据库 关系数据库就是基于关系模型的数据库系统.关系模型包含三部分:关系数据结构.关系操作集合.关系完整性约束. 关系数据结构 关系数据结构只包含一种数据结构--关系,从逻辑结构上看,关系就是一张二维表.前面提到,关系模型是基于严格的数学概念形成的数据模型,而关系的基础就是集合论.故需要从集合论角度理解关系数据结构的形式化定义. 域(domain) 域是一组具有相同数据类型的值的集合.如

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 Data technology has been extremely disruptive with open source playing a dominant role in shaping its evolution. While on one hand it has been disruptiv

OLAP Data Cube

A vision to see different beautiful views Cube is a shortcut for multidimensional dataset, given that data can have an arbitrary number of dimensions. The term hypercube is sometimes used, especially for data with more than three dimensions. Each cel

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 say that as IT professionals we are living in the golden age of data management era. As our software systems become more complex and more distributed,

Create the Data Access Layer

https://docs.microsoft.com/en-us/aspnet/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/create_the_data_access_layer This tutorial describes how to create, access, and review data from a database using ASP.NET Web Forms an

Persisting Data to the Device

Persisting Data to the Device Edit PagePage History Overview The Android framework offers several options and strategies for persistence: Shared Preferences - Easily save basic data as key-value pairs in a private persisted dictionary. Local Files -

nodes() Method (xml Data Type)

https://docs.microsoft.com/en-us/sql/t-sql/xml/nodes-method-xml-data-type The nodes() method is useful when you want to shred an xml data type instance into relational data. It allows you to identify nodes that will be mapped into a new row. Every xm

Introduction - Notes of Data Mining

Introduction @(Pattern Discovery in Data Mining)[Data Mining, Notes] Jiawei Han的Pattern Discovery课程笔记 Why data mining? data explosion and abundant(but unstructured) data everywhere drowning in data but starving in knowledge keyword: interdisciplinary

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 "stream processing", "event data", and "real-time", often related to technologies like Kafka, Storm, Samza, or Spark's Streaming module.