Monk
Monk

Reputation: 99

PHP : How to customing URL

Maybe this is an easy question.

I have a variable which save the user id in it.

$user_id = $_REQUEST['user_id'];

and then I have the URL like this :

try 
{
    $response = $client->delete('admin/user/**USER ID SHOULD HERE**',[
    'headers' => ['Authorization' => $_SESSION['login']['apiKey']]
    ]);
}

I already try to put variable $user_id like this admin/user/$user_id in that URL but nothing happens.'

This is the delete method()

    public function delete($url = null, array $options = [])
    {
        return $this->send($this->createRequest('DELETE', $url, $options));
    }

Am I wrote something wrong ? Thanks :)

Upvotes: 0

Views: 30

Answers (1)

Sharlike
Sharlike

Reputation: 1789

PHP variables will not be parsed inside of a single quoted string. You should use "admin/user/$user_id" if you want the variable's value to be used.

So you could write it like this:

$response = $client->delete("admin/user/$user_id",[

Or simply by concatenating the string and user id variable using .:

$response = $client->delete('admin/user/'.$user_id,[

Upvotes: 1

Related Questions