-
-
Save alexanderkuzmenko/f48c112f1f8a2df1697784977951399a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use yii\helpers\Html; | |
use yii\widgets\Pjax; | |
?> | |
<?php Pjax::begin(); ?> | |
<?= Html::a("Оновити", ['pjax/count', 'counter' => $counter], ['class' => 'btn btn-lg btn-primary']) ?> | |
<h1>Лічильник: <?= $counter ?></h1> | |
<?php Pjax::end(); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use yii\helpers\Html; | |
use yii\widgets\Pjax; | |
use yii\widgets\ActiveForm; | |
?> | |
<?php Pjax::begin(); ?> | |
<?php $form = ActiveForm::begin([ | |
'options' => ['data' => ['pjax' => true]], | |
]); ?> | |
<?= $form->field($model, 'first_name')->textInput() ?> | |
<?= $form->field($model, 'last_name')->textInput() ?> | |
<div class="form-group"> | |
<div class="col-lg-offset-1 col-lg-11"> | |
<?= Html::submitButton('OK', ['class' => 'btn btn-primary']) ?> | |
</div> | |
</div> | |
<?php ActiveForm::end(); ?> | |
<?= $fullName; ?> | |
<?php Pjax::end(); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use yii\helpers\Html; | |
use yii\widgets\Pjax; | |
?> | |
<?php Pjax::begin(); ?> | |
<?= Html::a("Оновити", ['pjax/get-server-time'], ['class' => 'btn btn-lg btn-primary']) ?> | |
<h1>Зараз: <?= $time ?></h1> | |
<?php Pjax::end(); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\controllers; | |
use app\models\Continent; | |
use app\models\StudentForm; | |
use app\models\WorldForm; | |
use Yii; | |
use yii\web\Controller; | |
class PjaxController extends Controller | |
{ | |
public function actionGetServerTime() | |
{ | |
return $this->render('get-server-time', ['time' => date("h:i:s")]); | |
} | |
public function actionCount($counter = 0) | |
{ | |
$counter++; | |
return $this->render('count', compact('counter')); | |
} | |
public function actionGetFullName() | |
{ | |
$model = new StudentForm(); | |
if (Yii::$app->request->isPjax) { | |
$model->load(Yii::$app->request->post()); | |
$fullName = $model->first_name . " " . $model->last_name; | |
return $this->render('get-full-name', compact('model', 'fullName')); | |
} | |
return $this->render('get-full-name', compact('model')); | |
} | |
public function actionWorldForm() | |
{ | |
$model = new WorldForm(); | |
$continents = Continent::find()->asArray()->all(); | |
$continent = null; | |
if (Yii::$app->request->isPjax) { | |
$model->load(Yii::$app->request->post()); | |
$continent = Continent::find()->where(['continent_id' => $model->continent_id])->one(); | |
} | |
return $this->render('world-form', [ | |
'model' => $model, | |
'continents' => $continents, | |
'continent' => $continent | |
]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\models; | |
use yii\base\Model; | |
class StudentForm extends Model | |
{ | |
public $first_name = ""; | |
public $last_name = ""; | |
public function rules() | |
{ | |
return [ | |
[['first_name', 'last_name'], 'required'] | |
]; | |
} | |
public function attributeLabels() | |
{ | |
return [ | |
'first_name' => "First Name", | |
'last_name' => "Surname" | |
]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use yii\helpers\ArrayHelper; | |
use yii\helpers\Html; | |
use yii\helpers\Url; | |
use yii\widgets\Pjax; | |
use yii\widgets\ActiveForm; | |
?> | |
<?php Pjax::begin([ | |
'id' => 'world-form-container' | |
]); ?> | |
<?php $form = ActiveForm::begin([ | |
'options' => ['data' => ['pjax' => true],], | |
'id' => 'world-form' | |
]); ?> | |
<?= $form->field($model, 'continent_id')->dropDownList(ArrayHelper::map($continents, 'continent_id', 'name'), [ | |
'id' => 'field-continent-id', | |
'onchange' => '$("#world-form").submit()' | |
]) ?> | |
<h2><?= $continent->name ?></h2> | |
<p><?= $continent->description ?></p> | |
<?php ActiveForm::end(); ?> | |
<?php Pjax::end(); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\models; | |
use yii\base\Model; | |
class WorldForm extends Model | |
{ | |
public $continent_id = 0; | |
public $country_id = 0; | |
public function rules() | |
{ | |
return [ | |
[['country_id', 'continent_id'], 'integer'] | |
]; | |
} | |
public function attributeLabels() | |
{ | |
return [ | |
'continent_id' => "Continent", | |
'country_id' => "Country", | |
]; // TODO: Change the autogenerated stub | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment