public function search($params){ $query = Post::find(); $dataProvider = new ActiveDataProvider([ # @1 'query' => $query, ]); # @2 $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'title', $this->title]) ->andFilterWhere(['like', 'creation_date', $this->creation_date]); # @3 return $dataProvider;}
At @1, $query this variable is assigned to the $dataProvider query property;
In the @2, $query have added some query conditions;
May I ask, at the @3
$dataProvider query property, how do you have the conditions that $query add to the @2?
Code Source
Reply content:
public function search($params){ $query = Post::find(); $dataProvider = new ActiveDataProvider([ # @1 'query' => $query, ]); # @2 $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'title', $this->title]) ->andFilterWhere(['like', 'creation_date', $this->creation_date]); # @3 return $dataProvider;}
At @1, $query this variable is assigned to the $dataProvider query property;
In the @2, $query have added some query conditions;
May I ask, at the @3
$dataProvider query property, how do you have the conditions that $query add to the @2?
Code Source
See http://php.net/manual/en/language.oop5.references.php
In PhP5, an object variable has no longer saved the value of the entire object. Just save an identifier to access the real object content.
class A{ public $foo = 1;}$a = new A;$b = $a;echo $b->foo; # 1$a->foo = 2;echo $b->foo; # 2