Database Reference
In-Depth Information
Figure 8-9. The Friends page
Listing 8-26. The HTML Code Snippet for Displaying the List of Friends
<div class="col-md-3">
<h3>Current Friends</h3>
<table class="table" id="following">
{{#following}}
<tr><td>{{firstname}} {{lastname}}</td><td><a href="#" id="{{username}}"
class="removefriend">Remove</a></td></tr>
{{/following}}
{{^following}}
No friends :(
{{/following}}
</table>
</div>
To search for users to follow, the user section contains a GET route /searchbyusername and passes in a username
value as part of the path. This route executes the searchByUsername method found in User class, showing the second
part of Listing 8-27. The first part of the WHERE clause in the method returns users whose username matches on a
wildcard String value. The second part of the WHERE clause in the method checks to make sure the users in the MATCH
clause are not already being followed by the current user.
Listing 8-27. The searchbyusername Route and searchByUsername Service Method
//search users by name
$app->get('/searchbyusername/:u', function($u) use ($app){
$users = User::searchByUsername($u,$_SESSION['username']);
echo '{"users": ' . json_encode($users) . '}';
});
 
Search WWH ::




Custom Search