Ionic - Pass User Details to Profile Page


#1

Hello i want to pass a a user details (First Name, Last Name, Biography, Telephone etc) after clicking on a link. I did that with NavParams and its good.

home.html

home.ts

UserPage(uid_fk,username) {
this.navCtrl.push(UserPage, { uid_fk: uid_fk, username:username });
}

userProfile.ts

constructor(
public common: Common,
public navCtrl: NavController,
public app: App,
public menuCtrl: MenuController,
public navParams: NavParams,
public authService: AuthService
) {
this.uid_fk = navParams.get(‘uid_fk’);
this.username = navParams.get(‘username’);
this.userProfile();
}

userProfile.html

{{uid_fk}}

{{username}}

And it works fine. But i want to know if i can call the user details using a PHP function like this.

PHP FUNCTION

function userDetails() {
$request = \Slim\Slim::getInstance()->request();
$data = json_decode($request->getBody());
$uid=$data->uid;

$sql = “SELECT uid,tour,username,name,emailNotifications,bio,email,friend_count,profile_pic,conversation_count,updates_count,profile_bg,group_count,profile_pic_status,profile_bg_position,verified,notification_created,photos_count,facebookProfile,twitterProfile,googleProfile,instagramProfile,gender,emailNotifications FROM users WHERE uid=:uid AND status=‘1’”;
try {
$db = getDB();
if($uid>0)
{
$stmt = $db->prepare($sql);
$stmt->bindParam(“uid”, $uid, PDO::PARAM_INT);
$stmt->execute();
$userDetails = $stmt->fetchAll(PDO::FETCH_OBJ);

$db = null;
echo '{"userDetails": ' . json_encode($userDetails) . '}';
}

} catch(PDOException $e) {
echo ‘{“error”:{“text40”:’. $e->getMessage() .’}}’;
}
}

And i want to call this function using this on userProfile.ts

userProfile() {
this.common.presentLoading();
this.authService.postData(this.userPostData, “userDetails”).then(

    result => {
        this.resposeData = result;
        if (this.resposeData.userDetails) {
            this.common.closeLoading();
            this.dataSet = this.resposeData.userDetails;
            console.log(this.dataSet);

        } else {
            console.log("No access");
        }
    },
    err => {
        //Connection failed message
    }
);

}

But i don’t know how to pass the user_id(uid) to the PHP function I know the this.authService.postData(this.userPostData, “userDetails”). its wrong but how i pass the uid_fk as uid?

$request = \Slim\Slim::getInstance()->request();
$data = json_decode($request->getBody());
$uid=$data->uid;


#2

PHP might as well be ancient Babylonian to me, but it looks like your backend is expecting a JSON object containing a uid property, so I would try this:

post(url, {uid: this.uid_fk})

#3

So you think that the best way to call the user details is how i did it thus far?

where do i put the post(url, {uid: this.uid_fk})

userProfile() {
this.common.presentLoading();
this.authService.postData(this.userPostData, “userDetails”).then(

    result => {
        this.resposeData = result;
        if (this.resposeData.userDetails) {
            this.common.closeLoading();
            this.dataSet = this.resposeData.userDetails;
            console.log(this.dataSet);

        } else {
            console.log("No access");
        }
    },
    err => {
        //Connection failed message
    }
);

}