How do I get the last uri segment from within a plugin (php) I have some validation that checks for a unique email when creating a new person. Works great.

When I am updating the person, it's no surprise the system won't let me save because the email I am saving already exists.

I am working on a condition that compares the id to the existing person to who is getting updated. 

Plugin_EmailValidator.php

...
$person = craft()-&gt;db-&gt;createCommand()
    -&gt;select('id, 'firstName, lastName')
    -&gt;from('people')
    -&gt;where('email=:email', array(':email' =&gt; $model['email']))
    -&gt;queryRow();

if(!empty($person)) {
    error_log('MATCH FOUND');

   // I have the id of the existing account. Need to compare against uri segment?
  $existingId = $person['id];
  $segment = craft()-&gt;request-&gt;getLastSegment();

  error_log($segment); // error!

   $message = Craft::t("Email already exists.");
   $this-&gt;addError($model, $attribute, $message);
}


This is what my url looks like:

/admin/plugin/controller/update/123


I see examples of using the request methods within twig, i'm trying to access it via php.

I've also tried this:

craft()-&gt;request-&gt;getQuery('update');


This will run without error, but it also returns nothing.
Have a look at the segments property (shortcut for getSegments() method) of the HttpRequestServices class, which returns an array of uri segments.

craft()-&gt;request-&gt;segments;


To get the last segment you could use php's end() or array_pop() method.

$segments = craft()-&gt;request-&gt;segments;
echo end($segments);