Answer the question
In order to leave comments, you need to log in
[[+content_image]]
Can this method be rewritten from Yii1 to Yi2?
Hello, I need help. I need to rewrite a method from Yii1 to Yii2.
The essence is this: the method accepts an array of values, for example
[["name" => "attr_date_end", "jointype" => "left join"]]
foreach ($attributes as $item) {
$criteria = new CDbCriteria;
criteria->select = (!is_array($this->getDbCriteria()->select) ? $this->getDbCriteria()->select : '') . ", " . $item['name'] . "." .$item['select'] . " as " . $item['name'];
$criteria->join = " " . $item['jointype'] . " cms_attributes_values " . $item['name'] . " on " . $item['name'] . ".id_obj=t.id AND " . $item['name'] . ".id_attr=" . $item['id_attr'] . " AND " . $item['name'] . ".id_tree=" . $item['id_tree'] . ($item['condition'] ? ' AND ' . str_replace("[id_variant]", $item['name'] . ".id_variant", str_replace("[id_val]", $item['name'] . ".id_val", str_replace("[text]", $item['name'] . ".text", $item['condition']))) : '');
$this->getDbCriteria()->mergeWith($criteria);
}
return $this;
$query = new Query();
$query->select = (!is_array($query->select) ? $query->select : '') . ", " . $item['name'] . "." . $item['select'] . " as " . $item['name'];
$query->join = " " . $item['jointype'] . " cms_attributes_values " . $item['name'] . " on " . $item['name'] . ".id_obj=t.id AND " . $item['name'] . ".id_attr=" . $item['id_attr'] . " AND " . $item['name'] . ".id_tree=" . $item['id_tree'] . ($item['condition'] ? ' AND ' . str_replace("[id_variant]", $item['name'] . ".id_variant", str_replace("[id_val]", $item['name'] . ".id_val", str_replace("[text]", $item['name'] . ".text", $item['condition']))) : '');
Answer the question
In order to leave comments, you need to log in
"nvalid argument supplied for foreach()" means that your $attributes is not an array. You are looking for the error in the wrong place.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question