「データは存在しますか?」というtblを確認したいと思います。データが tbl に存在しない場合は、1 つのページにリダイレクトします。すべてのコントローラーのアクションに同じコードを配置せずにどうすればよいですか?
if(Company::model()->exists() == false)
            $this->redirect(array('site/create'));
すべてのコントローラーのすべてのアクションの前にこのロジックを実行したい場合runは、基本コントローラー クラスのメソッドをオーバーライドできます (通常、これは という名前Controllerで、ディレクトリ内にありますprotected/components/)。
これを行う方法の例を次に示します。
public function run($actionID) {
    if ($this->route != 'site/create' && Company::model()->exists() === false) {
        $this->redirect('site/create');
    }
    else {
        parent::run($actionID);
    }
}
So you want to perform a query, and if there are no results redirect to another page?
$model = YourModel::model()->find("your query goes here");
if (empty($model)){
    $this->redirect("redirect/url/here");
}
If you want to execute this on every page "load", you can put it in the Controller.php (protected/components/Controller.php) by creating an init function like so:
public function init() {
    // anything here will be executed when any controller/action is called
}