arrays - How to use findAll() in yii2? -
i want know how can data of user
array id where
condition
in yii
this
$students = student::model()->findall("id in ({$_post['studentids']})");
or
$userdtls = student::model ()->findallbyattributes ( array ( 'id' => explode ( ",", $_post ['studentids'] ) ) );
now in yii2
cdbcriteria
not there, approach should use achieve same thing??
i have tried returns data first id in array
$result = users::findall([ 'id'=> $_post ['keylist']]);
in documentation written can use this
$result = users::findall([1,488,489]);
but array $_post['keylist']
this
keylist{ 0='1' 1='5' 2='8' }
i have tried
$ids = \yii::$app->request->post('keylist', []); $result = users::findall($ids);
and still returns data first id in array here screenshot
thats why doesnt work guess
thank
$users = users::findall($ids);
correct approach.
see can pass in $ids
in official docs here.
as explained here, should never trust data $_post
, check existence , validate before using.
example of getting , check existence yii2:
$ids = \yii::$app->request->post('ids');
or just:
$ids = isset($_post['ids']) ? $_post['ids'] : null;
for more complex cases i'd recommend create separate search model , use validation, see gii's crud example.
update: pay attention pass $ids
.
Comments
Post a Comment