One of the most important parts of any application is the ability to search for and discover new content. For this application, we'll be implementing a search method that will allow users to search for content and users. To do this, we'll check whether the query string in our search method contains the @
character. If it does, we'll perform a second search for that user and display information about that user in our view. We'll implement that method as follows:
We'll start by implementing
actionSearch()
as follows:public function actionSearch() {}
We'll then retrieve the query string from our
$_GET
parameters and define the scope for our models:$query = isset($_GET['q']) ? $_GET['q'] : NULL; $users = $shares = NULL;
Then, as long as there is a query to run against, we'll create two
CDbCriteria
objects; one for users and the other for shares:if ($query != NULL) { $userCriteria = new CDbCriteria; $searchCriteria = new CDbCriteria; }
Within this
if
bracket, we'll first...