PHP code example of alexgivi / yii2-require-modal

1. Go to this page and download the library: Download alexgivi/yii2-require-modal library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alexgivi / yii2-require-modal example snippets


<?= \alexgivi\ 'Complete form'
    'url' => ['test-controller/test-mpose()
         ->addDateField('date', 'Date', date('d.m.Y'))
         ->addNumberField('number', 'Number')
         ->addTextField('text', 'Text')
         ->addTextArea('textarea', 'Big Text')
         ->addDropDownList('selected', 'List', SomeClass::$someData)
]); 

class TestController extends yii\web\Controller
{
    public function actionTestRequire()
    {
        $date = Yii::$app->request->post('date');
        $number = Yii::$app->request->post('number');
        $text = Yii::$app->request->post('text');
        // ...
    }
}

/**
 * @var $model SomeModel
 */

 ...

<?= \alexgivi\te', 'id' => $model->id],
    'model, 'number_field')
         ->addTextField($model, 'name')
         ->addTextArea($model, 'description')
         ->addDropDownList($model, 'type', SomeModel::$typeNames)
         ->addHiddenField('redirect', Yii::$app->request->url)
]); 

class SomeModelController extends yii\web\Controller
{
    public function actionUpdate($id)
    {
        $model = $this->loadModel($id);

        if ($model->load($_POST) && $model->save()) {
            return $this->redirect(isset($_POST['redirect']) ?
                $_POST['redirect'] : ['view', 'id' => $model->id]);
        }

        return $this->render('update', ['model' => $model]);
    }
}

/**
 * @var $model SomeModel
 */

 $model = new SomeModel(); 

class SomeModelController extends yii\web\Controller
{
    public function actionCreate()
    {
        $model = new SomeModel();

        if ($model->load($_POST) && $model->save()) {
            return $this->redirect(isset($_POST['redirect']) ?
                $_POST['redirect'] : ['view', 'id' => $model->id]);
        }

        return $this->render('create', ['model' => $model]);
    }
}