Book Image

Yii Project Blueprints

By : Charles R. Portwood ll
Book Image

Yii Project Blueprints

By: Charles R. Portwood ll

Overview of this book

Table of Contents (15 chapters)
Yii Project Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Searching for shares


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:

  1. We'll start by implementing actionSearch() as follows:

    public function actionSearch() {}
  2. 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;
  3. 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;
    }
  4. Within this if bracket, we'll first...