Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //view////////////////////////////////////////////////////////////////////////////////////////////////////////
- <?php
- use yii\helpers\Html;
- use yii\widgets\ActiveForm;
- ?>
- <div class="ajax">
- <?php $form = ActiveForm::begin(); ?>
- <?= $form->field($model, 'text') ?>
- <div id="my"></div>
- <div class="form-group" id="my">
- <?= Html::submitButton('Submit', [
- 'class' => 'btn btn-primary',
- 'name' => 'contact-button',
- 'onclick'=>'$.ajax({
- url: "http://localhost/basic/web/index.php?r=ajax/ajax",
- type: "post",
- data: "555555555555555",
- success: function(response) {document.getElementById("my").innerHTML = document.getElementById("my").innerHTML+"Hello Dolly."+date;
- },
- error: function(response) {alert("не заебись")}
- })'
- ]) ?>
- </div>
- <?php ActiveForm::end(); ?>
- </div><!-- ajax -->
- ///AjaxController////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- <?php
- namespace app\controllers;
- use Yii;
- class AjaxController extends \yii\web\Controller
- {
- public function actionIndex()
- {
- $model = new \app\models\ajax();
- if ($model->load(Yii::$app->request->post())) {
- if ($model->validate()) {
- // form inputs are valid, do something here
- return 1;
- }
- }
- return $this->render('index', [
- 'model' => $model,
- ]);
- }
- public function actionAjax()
- {
- $n = array('min' => date("i"), "sec" => date("s"));
- echo json_encode($n);
- //$model = new \app\models\ajax();
- //$link = mysqli_connect("localhost", "root", "", "yii");if (mysqli_connect_errno()) {printf("Не удалось подключиться: %s\n", mysqli_connect_error());exit();} else echo 'подключились';
- //$link->set_charset("utf8") ;
- //$a='fgjgfhjfghj';
- //$insert = mysqli_multi_query($link,"INSERT INTO `yii`.`ajax` (`id`, `text`) VALUES (NULL, '$a')")or die (mysqli_error($link));
- }
- }
- ///////////////models///////////////////////////////////////////////////////////////////////
- <?php
- namespace app\models;
- use Yii;
- /**
- * This is the model class for table "ajax".
- *
- * @property integer $id
- * @property string $text
- */
- class Ajax extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'ajax';
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['text'], 'required'],
- [['text'], 'string']
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'text' => 'Text',
- ];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement