Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.80 KB | None | 0 0
  1. //view////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. <?php
  3.  
  4. use yii\helpers\Html;
  5. use yii\widgets\ActiveForm;
  6.  
  7.  
  8. ?>
  9. <div class="ajax">
  10.  
  11.     <?php $form = ActiveForm::begin(); ?>
  12.  
  13.         <?= $form->field($model, 'text') ?>
  14.     <div id="my"></div>
  15.         <div class="form-group" id="my">
  16.             <?= Html::submitButton('Submit', [
  17.                     'class' => 'btn btn-primary',
  18.                     'name' => 'contact-button',
  19.                     'onclick'=>'$.ajax({
  20.                         url: "http://localhost/basic/web/index.php?r=ajax/ajax",
  21.                         type: "post",
  22.                         data: "555555555555555",
  23.                         success: function(response) {document.getElementById("my").innerHTML = document.getElementById("my").innerHTML+"Hello Dolly."+date;
  24.                         },
  25.                         error: function(response) {alert("не заебись")}
  26.                     })'
  27.                    
  28.                    
  29.                     ]) ?>
  30.         </div>
  31.     <?php ActiveForm::end(); ?>
  32.  
  33.  
  34. </div><!-- ajax -->
  35. ///AjaxController////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  36. <?php
  37.  
  38. namespace app\controllers;
  39. use Yii;
  40. class AjaxController extends \yii\web\Controller
  41. {
  42.  
  43.  
  44.     public function actionIndex()
  45.     {
  46.         $model = new \app\models\ajax();
  47.  
  48.         if ($model->load(Yii::$app->request->post())) {
  49.             if ($model->validate()) {
  50.                 // form inputs are valid, do something here
  51.                 return 1;
  52.             }
  53.         }
  54.  
  55.         return $this->render('index', [
  56.             'model' => $model,
  57.         ]);
  58. }
  59.  
  60.  
  61. public function actionAjax()
  62.     {
  63.  
  64. $n = array('min' => date("i"), "sec" => date("s"));
  65.     echo json_encode($n);
  66.  
  67.  
  68.         //$model = new \app\models\ajax();
  69.         //$link = mysqli_connect("localhost", "root", "", "yii");if (mysqli_connect_errno()) {printf("Не удалось подключиться: %s\n", mysqli_connect_error());exit();} else echo 'подключились';
  70.         //$link->set_charset("utf8") ;
  71.         //$a='fgjgfhjfghj';
  72.         //$insert = mysqli_multi_query($link,"INSERT INTO `yii`.`ajax` (`id`, `text`) VALUES (NULL, '$a')")or die (mysqli_error($link));
  73.        
  74.  
  75.     }
  76.    
  77.    
  78.    
  79.    
  80.    
  81.    
  82. }
  83.  
  84.  
  85. ///////////////models///////////////////////////////////////////////////////////////////////
  86. <?php
  87.  
  88. namespace app\models;
  89.  
  90. use Yii;
  91.  
  92. /**
  93.  * This is the model class for table "ajax".
  94.  *
  95.  * @property integer $id
  96.  * @property string $text
  97.  */
  98. class Ajax extends \yii\db\ActiveRecord
  99. {
  100.     /**
  101.      * @inheritdoc
  102.      */
  103.     public static function tableName()
  104.     {
  105.         return 'ajax';
  106.     }
  107.  
  108.     /**
  109.      * @inheritdoc
  110.      */
  111.     public function rules()
  112.     {
  113.         return [
  114.             [['text'], 'required'],
  115.             [['text'], 'string']
  116.         ];
  117.     }
  118.  
  119.     /**
  120.      * @inheritdoc
  121.      */
  122.     public function attributeLabels()
  123.     {
  124.         return [
  125.             'id' => 'ID',
  126.             'text' => 'Text',
  127.         ];
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement