working on it ...

Filters

Explore Public Snippets

Sort by

Found 299 snippets matching: yii2

    public by kbudylov modified Jan 26, 2017  1690  14  5  0

    Yii2 $form->field

    <?= $form->field($model,'field',[
      //'template' => '{input}',
      //'options' => [
        //'class' => ''
      //]
    ])->textField([
      //'class' => ''
    ]) ?>

    public by tneumiller modified Apr 14, 2015  2402  1  3  0

    install YII2

    sudo composer global require "fxp/composer-asset-plugin:1.0.0-beta2"
    
    
    composer create-project --prefer-dist yiisoft/yii2-app-basic cmsprime
    
    
    composer require --prefer-dist yiisoft/yii2-bootstrap
    
     composer require kartik-v/yii2-widgets "*"
    

    public by tneumiller modified Apr 16, 2015  1635  0  2  0

    yii2

     
    sudo composer global require "fxp/composer-asset-plugin:1.0.0-beta2"
    
    
    composer create-project --prefer-dist yiisoft/yii2-app-basic cmsprime
    
    
    composer require --prefer-dist yiisoft/yii2-bootstrap
    
     composer require kartik-v/yii2-widgets "*"
    
    composer require kartik-v/yii2-grid "*"
    

    external by r3verser modified Oct 18, 2014  19279  240  5  2

    Yii2 Redirects all users to login page if not logged in

    Yii2 Redirects all users to login page if not logged in: AccessBehavior.php
    PHP
    <?php
    
    /*
     * In configuration file
     * ...
     * 'as AccessBehavior' => [
     *    'class' => '\app\components\AccessBehavior'
     * ]
     * ...
     * (c) Artem Voitko <r3verser@gmail.com>
     *
     * For the full copyright and license information, please view the LICENSE
     * file that was distributed with this source code.
     */
    
    namespace app\components;
    
    
    use yii\base\Behavior;
    use yii\console\Controller;
    use yii\helpers\Url;
    
    /**
     * Redirects all users to login page if not logged in
     *
     * Class AccessBehavior
     * @package app\components
     * @author  Artem Voitko <r3verser@gmail.com>
     */
    class AccessBehavior extends Behavior
    {
        /**
         * Subscribe for events
         * @return array
         */
        public function events()
        {
            return [
                Controller::EVENT_BEFORE_ACTION => 'beforeAction'
            ];
        }
    
        /**
         * On event callback
         */
        public function beforeAction()
        {
            if (\Yii::$app->getUser()->isGuest &&
                \Yii::$app->getRequest()->url !== Url::to(\Yii::$app->getUser()->loginUrl)
            ) {
                \Yii::$app->getResponse()->redirect(\Yii::$app->getUser()->loginUrl);
            }
        }
    
    
    }
    
    

    external by Nur Hidayat modified Sep 11, 2015  217  0  3  0

    Setting web.config untuk Yii2 basic

    Setting web.config untuk Yii2 basic: web.config
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <connectionStrings>
            <add connectionString="server=ap-cdbr-azure-southeast-a.cloudapp.net;User Id=user;database=proxima3;password=pass" name="proxima3" providerName="MySql.Data.MySqlClient" />
        </connectionStrings>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="Yii2 WebApp Redirect" stopProcessing="true">
                        <match url="^$" />
                        <action type="Redirect" url="/web" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    
    
    

    external by Ramil Ismakov modified Mar 4, 2015  205  1  2  0

    yii2 sort with multilanguage behaivour

    yii2 sort with multilanguage behaivour: yii2 sort with multilanguage.php
    $query = Shop::find()->multilingual();
    $query->joinWith(['translations']);
    
    //echo '<pre>', var_dump($query), '</pre>';die;
    
    $dataProvider = new ActiveDataProvider([
        'query' => $query,
    ]);
    
    $dataProvider->sort->attributes['title'] = [
        'asc' => ['shopLang.title' => SORT_ASC],
        'desc' => ['shopLang.title' => SORT_DESC],
        'label'=> Yii::t('shop', 'Title')
    ];
    
    
    

    external by schmunk42 modified Feb 9, 2015  149  0  2  0

    Yii2 module default view, showing all controllers in module (requires dmstr/yii2-application metadata)

    Yii2 module default view, showing all controllers in module (requires dmstr/yii2-application metadata): index.php
    <?php
    
    use yii\helpers\Inflector;
    
    ?>
    
    <div class="crud-default-index">
        <h1><?= $this->context->action->uniqueId ?></h1>
    
        <div class="box">
            <div class="box-header">
                <h3 class="box-title">Module Controllers</h3>
            </div>
            <div class="box-body">
                <?php
                foreach (\Yii::$app->getModule('admin')->getControllers($this->context->module->id) AS $i => $controller) {
                    echo yii\helpers\Html::a(
                        Inflector::camel2words(Inflector::id2camel($controller)),
                        ["/{$this->context->module->id}/$controller"],
                        ['class' => 'col-sm-3 btn btn-lg btn-default btn-flat']
                    );
                }
                ?>
                <div class="clearfix"></div>
            </div>
            <!-- /.box-body -->
        </div>
    
    </div>
    
    
    

    external by beatcode modified Dec 21, 2014  171  0  2  0

    yii2 Checkbox als Ja Nein

    yii2 Checkbox als Ja Nein: info.php
    <!--Or you could add a getDischargedLabel() function in your model :-->
    
    public function getDischargedLabel()
    {
    return $this->discharged ? 'Yes' : 'No';
    }
    
    <!--And in your gridview :-->
    
    [
    'attribute'=>'discharged',
    'value'=> 'dischargedLabel',
    ],
    
    
    

    external by Beat modified Jan 3, 2015  171  0  3  0

    Yii2 Google OpenId SuccessCallback

    Yii2 Google OpenId SuccessCallback: SiteController.php
     public function successCallback($client)
    {
    
        $attributes = $client->getUserAttributes();
    
        if (isset($attributes)) {
    
            $login = new LoginForm();
            $login->username = $attributes['contact/email'];
            $login->password = $attributes['contact/email'];
    
            if ($login->login()) {
                $this->Welcome();
    
            } else {
    
                /* Registrieren*/
                $model = new \app\models\User;
                $model->username = $attributes['contact/email'];
                $model->password =  sha1($attributes['contact/email']);
    
                if ($model->save()) {
    
                    // automatisch einloggen nach der Anmeldung
                    $login = new LoginForm();
                    $login->username = $attributes['contact/email'];
                    $login->password = $attributes['contact/email'];
    
                    if ($login->login()) {
                        $this->Welcome();
    
                    }
                }
            }
        }
            
    }
    
    
    

    external by marcuzy modified Feb 29, 2016  160  0  2  0

    Оторбражение дебагера Yii2 только для юзера с ролью админ

    Оторбражение дебагера Yii2 только для юзера с ролью админ: debug_only_admin.php
    <?php
    //из config.php
    if (YII_DEBUG) {
        $config['bootstrap'][] = 'debug';
        $config['modules']['debug'] = [
            'class' => 'yii\debug\Module',
            'allowedIPs' => ['127.0.0.1', '::1', '192.168.33.1', '*'],
            'on beforeAction'=>function($event) {
                //суть
                $event->isValid = nil(Yii::$app->user->getIdentity())->hasRole(\common\models\User::ROLE_ADMINISTRATOR);
            },
        ];
    }
    
    
    • Public Snippets
    • Channels Snippets