private function searchSubAccount($queryObject) { $criteria = new CDbCriteria(); $criteria->compare("main_account", $queryObject->main_account); $criteria->compare("username", $queryObject->username); $criteria->compare("password", $queryObject->password); return SubAccount::model()->findAll($criteria); }
public function actionExportSubAccount() { $fileName = 'All Sub Account credentias-' . date("Y-m-d"); header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private", false); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"{$fileName}.csv\";"); header("Content-Transfer-Encoding: binary"); $csvFile = sys_get_temp_dir() . '/' . uniqid() . '.csv'; $csvFileObj = fopen($csvFile, "w+"); $allSubAccounts = SubAccount::model()->findAll(); foreach ($allSubAccounts as $key => $currentSubAccount) { /*write to csv*/ fputcsv($csvFileObj, array($currentSubAccount->username, $currentSubAccount->password)); } fclose($csvFileObj); echo file_get_contents($csvFile); /*download file*/ }