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

enter image description here

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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -