Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Active Form :: Input Text:
- ============================
- <?= Html::activeLabel($user, 'email'); ?>
- <?= Html::activeTextInput($user, 'email'); ?>
- <?= Html::error($user, 'email'); ?>
- <?= $form->field($model, 'id',['options' => ['class' => ''],'template' => '{input}',])->input('hidden') ?>
- // with label
- <?= $form->field($model,'inserttime')->hiddenInput()->label('') ?>
- // Placeholder
- <?= $form->field($model, 'username')->textInput()->hint('Please enter your name')->label('Name') ?>
- //HTML5 fields
- <?= $form->field($model, 'email')->input('email') ?>
- //uploading multiple files or selecting multiple items
- <?=
- // allow multiple files to be uploaded:
- echo $form->field($model, 'uploadFile[]')->fileInput(['multiple'=>'multiple']);
- // allow multiple items to be checked:
- echo $form->field($model, 'items[]')->checkboxList(['a' => 'Item A', 'b' => 'Item B', 'c' => 'Item C']);
- ?>
- ///customize a label within a view using the following code:/
- <?= $form->field($model, 'name')->label('Your Name') ?>
- <?= $form->field($model, 'email')->label('Your Email') ?>
- ////// Dropdown Menu with List Model
- ===============================================================
- <?php
- use app\models\Menupanel;
- use yii\helpers\ArrayHelper;
- $form->field($model, 'c_parentid')->dropDownList(ArrayHelper::map(Menupanel::find()->all(), 'id', 'c_name'), ['prompt'=>'- please select -'])->hint('Please select parent menu')->label('Parent Menu Type')
- ?>
- // Gridview Status -> Active or Inactive
- ==============================================================
- <?php
- [
- 'attribute'=> 'c_active',
- 'value'=>function ($model){
- if($model->c_active == 1){
- return "Active";
- }else{
- return "No Activity";
- }
- },
- 'filter' => true,
- ],
- ?>
- Resource
- ==============================
- http://www.yiiframework.com/wiki/653/displaying-sorting-and-filtering-model-relations-on-a-gridview/
- http://www.yiiframework.com/wiki/679/filter-sort-by-summary-data-in-gridview-yii-2-0/
- render-a-form-in-a-modal-popup-using-ajax/
- ==========================================
- http://www.yiiframework.com/wiki/690/render-a-form-in-a-modal-popup-using-ajax/
- PJAX:
- =====
- http://stackoverflow.com/questions/23953659/using-pjax-in-yii2-for-updating-a-div
- Javascript
- ==========
- http://pastebin.com/NKTi8KK4
- // Date Picker
- ================================================
- <?php $form->field($model,'c_expdate')->widget(DatePicker::className(),
- [
- 'language' => 'en',
- 'clientOptions' => [
- 'showAnim'=>'fold',
- 'changeMonth' => 'true',
- 'changeYear' => 'true',
- 'dateFormat' => 'yy-mm-dd',
- 'keyboardNavigation' => false,
- ],
- ]) ?>
- //detailView yii2
- =====================
- <?= DetailView::widget([
- 'model' => $model,
- 'attributes' => [
- 'id',
- 'c_name',
- 'c_desc',
- [
- 'attribute'=> 'c_active',
- 'value' => $model->c_active,
- ],
- ],
- ]) ?>
- find model data by ID
- ============================
- <?php
- $model = User::find()->where(['id' => $id])->all();
- ?>
- // Set Flash Message in View page:::
- =======================================
- <?php
- controlller:: Yii::$app->getSession()->setFlash('success', 'New password was saved.');
- ?>
- <?php
- use yii\bootstrap\Alert;
- ?>
- <?php
- if($flash = Yii::$app->session->getFlash('success')){
- echo Alert::widget(['options' => ['class' => 'alert-success'], 'body' => $flash]);
- }elseif($flash = Yii::$app->session->getFlash('error')){
- echo Alert::widget(['options' => ['class' => 'alert-error'], 'body' => $flash]);
- }
- ?>
- /// Dependable Dropdown in
- ====================================================
- in View ::
- ==========
- <?php
- <?= $form->field($model, 'c_parentid')->dropDownList([
- 'Module'=> ArrayHelper::map(Menupanel::find()->where(['c_type' => 'MODU'])->all(), 'id', 'c_name'),
- 'Menu'=> ArrayHelper::map(Menupanel::find()->where(['c_type' => 'MENU'])->all(), 'id', 'c_name'),
- 'Sub-Menu'=> ArrayHelper::map(Menupanel::find()->where(['c_type' => 'SUBM'])->all(), 'id', 'c_name')],
- [
- 'prompt'=>'- please select -',
- 'onchange'=>'
- $.post( "'.Yii::$app->urlManager->createUrl('/roledt/menu-item&id=').'"+$(this).val(),
- function( data ) {
- $( "#'.Html::getInputId($model, 'c_menuid').'" ).html( data );
- });
- '])->hint('Please select parent menu')->label('Parent Menu ID'); ?>
- <?= $form->field($model, 'c_menuid')->dropDownList(
- ['prompt'=>'- please select -'])->hint('Please select menu item')->label('Menu Item') ?>
- ?>
- in controller::
- ===============
- <?php
- public function actionMenuItem($id){
- $countMenu = Menupanel::find()
- ->where(['c_parentid' => $id])
- ->count();
- $menuItem = Menupanel::find()
- ->where(['c_parentid' => $id])
- ->orderBy('id ASC')
- ->all();
- if($countMenu>0){
- foreach($menuItem as $post){
- echo "<option value='".$post->id."'>".$post->c_name."</option>";
- }
- }
- else{
- echo "<option>- Nothing Found -</option>";
- }
- }
- ?>
- Action Buttons in Gridview :::
- =================================================================================
- <?php
- [
- 'class' => 'yii\grid\ActionColumn',
- 'header'=>'Action',
- 'template'=>'{view}{update}{info}',
- 'buttons' => [
- 'info' => function ($url, $model) {
- return Html::a('<span class="glyphicon glyphicon-info-sign"></span>', $url, [
- 'title' => Yii::t('app', 'Info'),
- ]);
- }
- ],
- 'urlCreator' => function ($action, $model, $key, $index) {
- if ($action === 'info') {
- $url = Yii::t('app', ['user/index', 'id'=>'1']); // your own url generation logic
- return $url;
- }
- }
- ]
- ?>
- popup- yii2
- ============
- http://stackoverflow.com/questions/23927579/how-can-i-show-the-default-login-page-as-modal-popup-in-yii2
- http://getbootstrap.com/javascript/#modals-usage
- https://toster.ru/q/76516
- // Modal ::
- ========================
- <!-- Button trigger modal -->
- <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal1">
- Launch
- </button>
- <!-- Modal -->
- <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
- <div class="modal-dialog">
- <div class="modal-content">
- <div class="modal-header">
- <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
- <h4 class="modal-title" id="myModalLabel"><?= $this->title; ?></h4>
- </div>
- <div class="modal-body">
- <?= $this->title; ?>
- </div>
- </div>
- </div>
- </div>
- OR
- ==
- <a href="javascript:void(0);" onclick="login();return false;">Login</a>
- <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
- <script>
- function login(){
- $.ajax({
- type:'POST',
- url:'index.php?r=roledt/create',
- success: function(data)
- {
- $('#myModal').html(data);
- $('#myModal').modal();
- }
- });
- }
- </script>
- <span data-dismiss="modal"><span aria-hidden="true"></span> </span>
- ////////////////////////////////////////////
- <?php Modal::begin([
- 'id' => 'modal',
- 'header' => '<h4>Hello world</h4>',
- 'toggleButton' => ['label' => 'click me'],
- 'class' => "btn btn-primary btn-lg",
- ]); ?>
- <?= $this->render('//site/about', [
- 'model' => $model,
- ]) ?>
- <?php Modal::end(); ?>
- // Render another file/folder
- =============================
- <?= $this->render('//site/about', [
- 'model' => $model,
- ]) ?>
- <?= \Yii::$app->view->renderFile('@app/views/site/about.php'); ?>
- /// SearchModel with Parameters from Controller
- ===============================================
- Controller:
- ==========
- <?php
- $searchModel1 = new RoledtSearch();
- $dataProvider = $searchModel1->searchDt(['RoledtSearch'=>['c_id'=>$id]]);
- ?>
- in SearchModel::
- ===============
- <?php
- $this->addCondition($query, 'c_id');
- OR ::::::::::::::::::::::::::::::::::::
- $query->andFilterWhere([
- 'z_roledt.c_id' => $this->c_id,
- ]);
- ?>
- /// Readonly in Form
- =======================
- <?= $form->field($model, 'TYPE')->input('TYPE', $model->isNewRecord ? ['readonly' => true]: ['readonly' => true])->hint('Please enter TYPE')->label('TYPE') ?>
- /// User Login System and Tocken peremeters:::
- ===============================================
- http://www.tuicool.com/articles/nMrIFj
- /// For loop for local images::::
- ==================================
- <?php for ($x=1; $x<=3; $x++) { ?>
- <div class="item">
- <img src="<?= Yii::$app->request->BaseUrl.'/images/banner/'.$x.'.png' ?>" alt="Image 001">
- <div class="carousel-caption">
- Pipeline Racks
- </div>
- </div>
- <?php } ?>
- /// Buttom with pop-up Image/content:
- ======================================
- <?php
- <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">Popup image</button>
- <div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
- <div class="modal-dialog">
- <div class="modal-content">
- <div class="modal-body">
- <img src="<?= Yii::$app->request->BaseUrl.'/images/banner'.'/2.png' ?>" class="img-responsive">
- </div>
- </div>
- </div>
- </div>
- ?>
- /// Bootstrap Photo gallery
- ===========================
- http://fearlessflyer.com/next-and-previous-buttons-bootstrap-photo-gallery/
- /// Detail View :::
- ====================
- <?php
- public function getMenuParent()
- {
- return $this->hasOne(Menupanel::className(), ['id' => 'c_parentid']);
- }
- in widget ::;
- <?= DetailView::widget([
- 'model' => $model,
- 'attributes' => [
- 'menuParent.c_name',
- ],
- ]) ?>
- ?>
- /// Grid View:
- =================
- <?php
- public $Rolehd;
- public function getRolehd()
- {
- return $this->hasOne(Rolehd::className(), ['id' => 'c_id']);
- }
- GridView::widget([
- 'dataProvider' => $dataProvider,
- 'filterModel' => $searchModel,
- 'columns' => [
- ['class' => 'yii\grid\SerialColumn'],
- [
- 'header'=> 'Role Header',
- 'attribute' => 'rolehd',
- 'value' => 'rolehd.c_name'
- ],
- ],
- ]);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment