Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
systems:yii2:examples [2018/05/16 12:17]
smayr [Flash Messages]
systems:yii2:examples [2018/10/04 17:05] (current)
ajdavis [Copy to Clipboard using Javascript]
Line 310: Line 310:
             'value' => '<div><b>'.description.'</b></div>',             'value' => '<div><b>'.description.'</b></div>',
         ],         ],
-        image:image,+         
 +        intro_image:image
 +        [ 
 +              'attribute' => 'intro_image', 
 +              'label'     => 'Intro Image', 
 +              'format'    => 'image', 
 +              'value'     => (!empty($model->intro_image) ? Yii::$app->urlManager->createUrl('').'media/'.$model->intro_image : ''), 
 +        ], 
 +        [ 
 +              'attribute' => 'intro_image', 
 +              'label'     => 'Intro Image', 
 +               
 +              // Add image size limit 
 +              'format' => 'raw', 
 +              'value'  => '<img src="'.(!empty($model->intro_image) ?  
 +                  Yii::$app->urlManager->createUrl('').'media/'.$model->intro_image :  
 +                  '') .  
 +                  '" style="width: 700px;"/>' 
 +        ],
                  
         // dates         // dates
Line 971: Line 989:
 <code php> <code php>
 <?php  <?php 
-use yii\helpers\Url+    // Method 1: Button 
-... +    \yii\helpers\Html::button('Privacy Policy',
-    // Method 1 +        'id'    => 'btnPrivacyPolicy', 
-    echo Html::a('Privacy Policy', ['site/privacy']);+        'class' => 'btn btn-default btn-sm', 
 +    ])
 +                 
 +    // Method 2: Link styled as button 
 +    echo \yii\helpers\Html::a('Privacy Policy', ['site/privacy']);
  
-    // Method 2 +    // Method 3: Link styled as button 
-    $url = urldecode(Url::toRoute(['site/privacy'])); +    $url = urldecode(\yii\helpers\Url::toRoute(['site/privacy'])); 
-    echo Html::a('Privacy Policy', $url);+    echo \yii\helpers\Html::a('Privacy Policy', $url);
          
-    // Method 3 +    // Method 4: Link styled as button 
-    echo Url::to(['site/privacy']); +    echo \yii\helpers\Url::to(['site/privacy']); 
 ?> ?>
 </code> </code>
Line 1508: Line 1530:
  
 === Modal Window === === Modal Window ===
 +  * See: [[systems:yii2:Modal Window]]
  
-<code php> 
-<?php 
-    $itemImage = (!empty($model->image_file) ?  
-        Yii::$app->homeUrl . 'img/data/' . Yii::$app->controller->id . "/{$model->image_file}" 
-        '' 
-    ); 
-     
-    // Image Thumbnail 
-    if(!empty($itemImage)) { 
-        echo "<img class='img-thumbnail' src='{$itemImage}' alt='Item Image'>"; 
-    } else { 
-        echo "<img class='img-thumbnail' src='data:image/png;base64," 
-            base64_encode(\app\models\Tool::generateEmptyPng()) . "'/>"; 
-    } 
  
- 
-    echo Html::a('<i class="fa fa-plus" aria-hidden="true"></i> ' . Yii::t('app', 'Add Image'),  
-        ['upload-image', 'id' => $model->id], ['class' => 'btn btn-default'] 
-    ); 
- 
-    // Modal to view image  
-    yii\bootstrap\Modal::begin([ 
-        'header' => '<h4>Item Image</h4>', 
-        'size'   => yii\bootstrap\Modal::SIZE_LARGE, 
-        'toggleButton' => [ 
-            'label' => '<i class="fa fa-image" aria-hidden="true"></i> ' . Yii::t('app', 'View Image'),  
-            'class' => 'btn btn-default' 
-        ], 
-    ]); 
- 
-    if(!empty($itemImage)) { 
-        echo "<img class='img-fluid' src='{$itemImage}' alt='Item Image'>"; 
-    } else { 
-        echo "<img class='img-fluid' src='data:image/png;base64," 
-            base64_encode(\app\models\Tool::generateEmptyPng()) . "'/>"; 
-    } 
-    echo '<div class="modal-footer">'; 
-    echo '    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>'; 
-    echo '</div>'; 
- 
-    yii\bootstrap\Modal::end();   
-?> 
-</code> 
 == Events == == Events ==
  
Line 1677: Line 1658:
             'createdAtAttribute' => 'created_at', // OR 'create_time', to override default field name             'createdAtAttribute' => 'created_at', // OR 'create_time', to override default field name
             'updatedAtAttribute' => 'updated_at', // OR 'update_time', to override default field name             'updatedAtAttribute' => 'updated_at', // OR 'update_time', to override default field name
-            'value' => new \yii\db\Expression('NOW()'),+            'value' => new \yii\db\Expression('NOW()'),  // for PHP/SQL datetime field 
 +            //'value' => time(),                         // for epoch time (unix) field
         ],         ],
         [         [
Line 2977: Line 2959:
 $dataProviderPrice->pagination->pageSizeLimit   = false; $dataProviderPrice->pagination->pageSizeLimit   = false;
 </code>         </code>        
 +
 +== Copy to Clipboard using Javascript ==
 +
 + # Add a reference to the //ClipboardJS// library either by using Yii2 registerJsFile or adding the file to ''assets\AppAsset.php''
 + # Add javascript to your page that creates an instance of ClipboardJS:
 +<code php>$this->registerJs("var clipboard = new ClipboardJS('.btn-clip');", \yii\web\View::POS_END);</code>
 + # Add a button that follows this logic:
 +<code html>
 +<i class="fa fa-copy btn btn-default btn-clip" data-clipboard-text="value-to-copy"></i>
 +</code>