public function test_1Action() { $model = Test::model(); $starttime = explode(' ', microtime()); for ($i = 0; $i < 1; $i++) { $data = $model->where('id', $i)->page(1, 4)->find(); } debug($data); //程序运行时间 $endtime = explode(' ', microtime()); $thistime = $endtime[0] + $endtime[1] - ($starttime[0] + $starttime[1]); $thistime = round($thistime, 3); echo "本网页执行耗时:" . $thistime . " 秒。" . time(); echo 'hello world'; }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { Yii::log("Mi primer log", "info", "application.controllers.SiteController"); Yii::log("eeeeee error", "error", "application.controllers.SiteController"); Yii::log("wwwwwwwwww warning", "warning", "application.controllers.SiteController"); Yii::log("Mi primer trace", "trace", "application.controllers.SiteController"); Yii::log("001#Venta en el sitio tal 1", "info", "application.controllers.SiteController.ref"); Yii::log("003#Venta en el sitio tal 2", "info", "application.controllers.SiteController.ref"); Yii::log("002#Venta en el sitio tal 3", "info", "application.controllers.SiteController.ref"); Yii::beginProfile("miProfileBucleFor", "application.controllers.SiteController"); for ($x = 0; $x < 100; $x++) { echo ""; } Yii::endProfile("miProfileBucleFor", "application.controllers.SiteController"); Yii::beginProfile("miProfileBucleFor", "application.controllers.SiteController"); sleep(1); Yii::endProfile("miProfileBucleFor", "application.controllers.SiteController"); Yii::app()->db->createCommand("SELECT * FROM test")->queryAll(); Test::model()->findAll(); // renders the view file 'protected/views/site/index.php' // using the default layout 'protected/views/layouts/main.php' $this->render('index'); }
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { if ($_GET['group_id'] == 1) { //check exist course and test created by a trainer if (Course::model()->checkCourse($id) && Test::model()->checkTest($id)) { Yii::app()->user->setFlash('unsuccess', ' Can not delete a trainer.'); $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'group_id' => $_GET['group_id'])); } // delete trainer $this->loadModel($id)->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { Yii::app()->user->setFlash('success', 'You did delete a trainer when: <br>- Not exist course created by trainer.<br>- Not exist test created by trainer.'); $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'group_id' => $_GET['group_id'])); } } elseif ($_GET['group_id'] == 2) { //Delete course trainee CourseTrainee::model()->deleteCourseTrainee($id); //Delete user test UserTest::model()->deleteUserTest($id); //Delete training log and training random question TrainingLog::model()->deleteTrainingLog($id); TrainingRandomquestion::model()->deleteTrainingRadomQuestion($id); //delete trainee $this->loadModel($id)->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser Yii::app()->user->setFlash('success', 'You did delete a trainee: <br>- Delete course trainee.<br>- Delete Training log and training random question.<br>- Delete user test and user answers.'); if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'group_id' => $_GET['group_id'])); } } elseif ($_GET['group_id'] == 3) { // delete training manager $this->loadModel($id)->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser Yii::app()->user->setFlash('success', 'You did delete a training manager.'); if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'group_id' => $_GET['group_id'])); } } elseif ($_GET['group_id'] == 4) { // delete team leader ATrainingTeam::deleteTeamleader($id); $this->loadModel($id)->delete(); // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser Yii::app()->user->setFlash('success', 'You did delete a team leader.'); if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'group_id' => $_GET['group_id'])); } } }
public function actionGeneratePdf() { $session = new CHttpSession(); $session->open(); Yii::import('application.extensions.giiplus.bootstrap.*'); require_once 'tcpdf/tcpdf.php'; require_once 'tcpdf/config/lang/eng.php'; if (isset($session['Test_records'])) { $model = $session['Test_records']; } else { $model = Test::model()->findAll(); } $html = $this->renderPartial('expenseGridtoReport', array('model' => $model), true); //die($html); $pdf = new TCPDF(); $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor(Yii::app()->name); $pdf->SetTitle('Test Report'); $pdf->SetSubject('Test Report'); //$pdf->SetKeywords('example, text, report'); $pdf->SetHeaderData('', 0, "Report", ''); $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, "Example Report by " . Yii::app()->name, ""); $pdf->setHeaderFont(array('helvetica', '', 8)); $pdf->setFooterFont(array('helvetica', '', 6)); $pdf->SetMargins(15, 18, 15); $pdf->SetHeaderMargin(5); $pdf->SetFooterMargin(10); $pdf->SetAutoPageBreak(TRUE, 0); $pdf->SetFont('dejavusans', '', 7); $pdf->AddPage(); $pdf->writeHTML($html, true, false, true, false, ''); $pdf->LastPage(); $pdf->Output("Test_002.pdf", "I"); }
/** * Returns the static model of the specified AR class. * Please note that you should have this exact method in all your CActiveRecord descendants! * @param string $className active record class name. * @return WTest the static model class */ public static function model($className = __CLASS__) { return parent::model($className); }
<?php $this->breadcrumbs = array($model->label(2) => array('index'), Yii::t('app', 'Manage')); $this->menu = array(array('label' => Yii::t('app', 'List') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' ' . $model->label(), 'url' => array('create'))); Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$.fn.yiiGridView.update('test2-grid', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n"); ?> <h1><?php echo Yii::t('app', 'Manage') . ' ' . GxHtml::encode($model->label(2)); ?> </h1> <p> You may optionally enter a comparison operator (<, <=, >, >=, <> or =) at the beginning of each of your search values to specify how the comparison should be done. </p> <?php echo GxHtml::link(Yii::t('app', 'Advanced Search'), '#', array('class' => 'search-button')); ?> <div class="search-form"> <?php $this->renderPartial('_search', array('model' => $model)); ?> </div><!-- search-form --> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'test2-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array('id', array('name' => 'test_id', 'value' => 'GxHtml::valueEx($data->test)', 'filter' => GxHtml::listDataEx(Test::model()->findAllAttributes(null, true))), 'name', array('class' => 'CButtonColumn'))));
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = Test::model()->with('integration', 'system', 'unit', 'validation')->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } /*if ( $model->integration != null ) $model = $model->integration; else if ( $model->system != null ) $model = $model->system; else if ( $model->unit != null ) $model = $model->unit; else if ( $model->validation != null ) $model = $model->validation; else throw new CHttpException(404,'The requested page does not exist.');*/ return $model; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Test the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Test::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }