Advertisement
susilolabs

Js rebind yii1, inline edit

Sep 23rd, 2016
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. <?php
  2. class Controller extends CController
  3. {
  4.     /**
  5.      * Render json data
  6.      *
  7.      * @param array $data
  8.      */
  9.     protected function renderJson($data) {
  10.         $this->layout = false;
  11.         header('Content-Type: application/json');
  12.         echo CJSON::encode($data);
  13.         Yii::app()->end();
  14.     }
  15.  
  16.     protected function renderCsv($data) {
  17.         $this->layout = false;
  18.         header('Content-Type: text/csv');
  19.         echo $data;
  20.         Yii::app()->end();
  21.     }  
  22.  
  23.     /**
  24.      * Render javascript data
  25.      *
  26.      * @param array $data
  27.      */
  28.     protected function renderJs($data, $encode=false) {
  29.         $this->layout = false;
  30.         header('Content-Type: application/javascript');
  31.         echo ($encode? CJSON::encode($data): $data);
  32.         Yii::app()->end();
  33.     }
  34. }
  35.  
  36. class SiteController extends Controller
  37. {
  38.     public function actionGetDiscountScript() {
  39.         $url = $this->createAbsoluteUrl('savediscount');
  40.         $js = <<<JS
  41. $(document).bind('ready', function(evt) {
  42. // mycode
  43. });
  44. JS;
  45.         $this->renderJs($js);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement