YII is used as the background, and Yii AR cannot meet the requirements. In a hurry, what should I do?

Source: Internet
Author: User
I use YII as the PHP framework. One of the functions is to query people nearby. My code does this: {code...} I use Mysql to calculate the distance. But when I print it out, I find that the distance attribute is not: {code...} That is, Yii only uses the YII in the user table as the PHP framework. One of the functions is to query people nearby.
My code does this:

Class NearByController extends Controller {// someone nearby is found. No filtering is available. Where is distance? Public function actionIndex () {$ latitude = UserRefreshForm: model ()-> getLatitude (); $ longdistance = UserRefreshForm: model ()-> getlongdistance (); $ criteria = new CDbCriteria (); $ nearPersons = MGetNear: getNearPersonsNoOrder (); $ criteria-> select ='t. *, (ACOS (SIN (('. $ latitude. '* 3.1415)/180) * SIN (tbl_myr_refresh.latitude * 3.1415)/180) + COS (('. $ latitude. '* 3.1415)/180) * COS (tbl_myr_refresh.latitude * 3.1415)/180) * COS (('. $ longpolling. '* 3.1415)/180-(tbl_myr_refresh.long1_* 3.1415)/180) * 6378.137) as distance'; $ criteria-> join = 'left JOIN tbl_myr_refresh ON tbl_myr_refresh.userId = t. userid'; $ criteria-> addInCondition ('t. userid', $ nearPersons); $ criteria-> order = 'distance ASC '; $ UserModel = User: model (); $ total = $ UserModel-> count ($ criteria); $ pager = new CPagination ($ total); $ pager-> pageSize = 10; $ pager-> applyLimit ($ criteria); $ userList = $ UserModel-> findAll ($ criteria); p ($ userList );}

I use Mysql to calculate the distance.
But when I print it out, I find that there is no distance attribute:

Array ([0] => User Object ([password1] => [password2] => [geohash] => [_ new: CActiveRecord: private] => [_ attributes: CActiveRecord: private] => Array ([userId] => 3 [username] => [password] => c3284d0f94606de1fd2af172aba15bf3 [email] => 741691740@qq.com [phoneNumber] => [birthday] => [gender] => 1 [homeland] => Sichuan Nanchong [wantWhere] => [registerDate] => 2014-06-27 [smallAvatar] => region [bigAvatar] => region [qrcode] => [isStudent] => 1 [wentWhere] => [md5] => role [sessionId] => o5fcapmo7clfiiua717n1aa525 [iemi] => 123456789) [_ related: CActiveRecord: private] => Array () [_ c: CActiveRecord: private] => [_ pk: CActiveRecord: private] => 3 [_ alias: CActiveRecord: private] => t [_ errors: CModel: private] => Array () [_ validators: CModel: private] => [_ scenario: CModel: private] => update [_ e: CComponent: private] => [_ m: CComponent: private] => ))

That is, Yii only prints out some of the user tables. However, the distance attribute is not printed!
For help. YII tells me how to obtain this distance attribute?

Reply content:

I use YII as the PHP framework. One of the functions is to query people nearby.
My code does this:

Class NearByController extends Controller {// someone nearby is found. No filtering is available. Where is distance? Public function actionIndex () {$ latitude = UserRefreshForm: model ()-> getLatitude (); $ longdistance = UserRefreshForm: model ()-> getlongdistance (); $ criteria = new CDbCriteria (); $ nearPersons = MGetNear: getNearPersonsNoOrder (); $ criteria-> select ='t. *, (ACOS (SIN (('. $ latitude. '* 3.1415)/180) * SIN (tbl_myr_refresh.latitude * 3.1415)/180) + COS (('. $ latitude. '* 3.1415)/180) * COS (tbl_myr_refresh.latitude * 3.1415)/180) * COS (('. $ longpolling. '* 3.1415)/180-(tbl_myr_refresh.long1_* 3.1415)/180) * 6378.137) as distance'; $ criteria-> join = 'left JOIN tbl_myr_refresh ON tbl_myr_refresh.userId = t. userid'; $ criteria-> addInCondition ('t. userid', $ nearPersons); $ criteria-> order = 'distance ASC '; $ UserModel = User: model (); $ total = $ UserModel-> count ($ criteria); $ pager = new CPagination ($ total); $ pager-> pageSize = 10; $ pager-> applyLimit ($ criteria); $ userList = $ UserModel-> findAll ($ criteria); p ($ userList );}

I use Mysql to calculate the distance.
But when I print it out, I find that there is no distance attribute:

Array ([0] => User Object ([password1] => [password2] => [geohash] => [_ new: CActiveRecord: private] => [_ attributes: CActiveRecord: private] => Array ([userId] => 3 [username] => [password] => c3284d0f94606de1fd2af172aba15bf3 [email] => 741691740@qq.com [phoneNumber] => [birthday] => [gender] => 1 [homeland] => Sichuan Nanchong [wantWhere] => [registerDate] => 2014-06-27 [smallAvatar] => region [bigAvatar] => region [qrcode] => [isStudent] => 1 [wentWhere] => [md5] => role [sessionId] => o5fcapmo7clfiiua717n1aa525 [iemi] => 123456789) [_ related: CActiveRecord: private] => Array () [_ c: CActiveRecord: private] => [_ pk: CActiveRecord: private] => 3 [_ alias: CActiveRecord: private] => t [_ errors: CModel: private] => Array () [_ validators: CModel: private] => [_ scenario: CModel: private] => update [_ e: CComponent: private] => [_ m: CComponent: private] => ))

That is, Yii only prints out some of the user tables. However, the distance attribute is not printed!
For help. YII tells me how to obtain this distance attribute?

(ACOS(SIN(('.$latitude.'* 3.1415) / 180 ) *SIN((tbl_myr_refresh.latitude * 3.1415) / 180 ) +COS(('.$latitude.'* 3.1415) / 180 ) * COS((tbl_myr_refresh.latitude * 3.1415) / 180 ) *COS(('.$longitude .'* 3.1415) / 180 - (tbl_myr_refresh.longitude * 3.1415) / 180 ) ) * 6378.137) as distance

The alias must be borrowed from an existing field in the table. Otherwise, the value cannot be obtained from the row object.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.