简体   繁体   中英

YII CDBCriteria filter columns

I fairly new to YII and still trying to understand it all. However from what I can tell when you do something like

    yourModel->findAll(criteria)

Is like "Select * from"? or is it more like "Select yourModel->Attributes from"? In either case I was wondering in CDbCriteria is there a way to remove columns from the select. My case I have a user table that contains password I would like to prevent this from being added in the query.

Thanks,

Ofcourse you can select specific columns, just use the select property of CDbCriteria :

$criteria=new CDbCriteria();
$criteria->select='column1, column2';// or you can use array array('column1','column2')
$manymodels=$yourmodel->findAll($criteria);

So it is more like : "Select criteria->select from yourmodelclass' dbtable".

Note that findAll() will return you an array of models.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM