<?php
namespace frontend\models;
class ListtModel extends \yii\db\ActiveRecord
{
public static function tableName()
{
return 'listt';
}
public function one(){
return $this->find()->asArray()->one();
}
//入库一维数组
public function add($data)
{
$this->setAttributes($data,false);
$this->isNewRecord = true;
$this->save();
return $this->id;
}
//入库二维数组
public function addAll($data){
$ids=array();
foreach($data as $attributes)
{
$this->isNewRecord = true;
$this->setAttributes($attributes);
// $this->save();
$this->save()&& array_push($ids,$this->id) && $this->id=0;
}
return $ids;
}
public function rules()
{
return [
[['title','content'],'required'
]];
}
/**
* @param $files 字段名
* @param $values 是一个数组值不是字符转
* @return int 影响行数
*/
public function del($field,$values){
// $res = $this->find()->where(['in', "$files", $values])->deleteAll();
$res=$this->deleteAll(['in', "$field", "$values"]);
return $res;
}
/**
* @param $data 修改数据
* @param $where 修改条件
* @return int 影响行数
*/
public function upda($data,$where){
$result = $this->updateAll($data,$where);
// return $this->id;
return $result;
}
// public function del($files,$values){
// $res = $this->find()->where(["$files"=>"$values"])->one()->delete();
// }
}
字符串数组互转方式;
$array=explode(separator,$string);
$string=implode(glue,$array);