Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Controller extends CController
- {
- /**
- * Render json data
- *
- * @param array $data
- */
- protected function renderJson($data) {
- $this->layout = false;
- header('Content-Type: application/json');
- echo CJSON::encode($data);
- Yii::app()->end();
- }
- protected function renderCsv($data) {
- $this->layout = false;
- header('Content-Type: text/csv');
- echo $data;
- Yii::app()->end();
- }
- /**
- * Render javascript data
- *
- * @param array $data
- */
- protected function renderJs($data, $encode=false) {
- $this->layout = false;
- header('Content-Type: application/javascript');
- echo ($encode? CJSON::encode($data): $data);
- Yii::app()->end();
- }
- }
- class SiteController extends Controller
- {
- public function actionGetDiscountScript() {
- $url = $this->createAbsoluteUrl('savediscount');
- $js = <<<JS
- $(document).bind('ready', function(evt) {
- // mycode
- });
- JS;
- $this->renderJs($js);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement