Change Layout Template in Yii Framework 2

Today We are going to change the layout of a module in Yii Framework 2.

1: Go to https://almsaeedstudio.com/ or AdminLTE-2.3.0 to download the template.

2: Extract it to module_name/web/

      a: replace module_name with your module name like here my module name is backend

      b: Rename the folder as you desire. Here I renamed it to template. Now my folder directory looks like backend/web/template/

3: Go to module_name/views/layouts/

      a: Create files as per your choice like header.php, footer.php, menu.php, etc.php. Here we are going to create three files named header.php, side_bar.php, footer.php assuming that we have one file inside layouts folder named main.php. If not create one with the same name.

4: Go to module_name/web/template/ open index.html in one of your favourite text editor

      a: copy the header part code as highlighted in screenshot, and past it to header.php

Header Part of Dashboard

      b: copy the header part code as highlighted in the screenshot, and past it to side_bar.php

Sidebar of Dashboard

      c: copy the header part code as highlighted in screenshot, and past it to footer.php

Footer of Dashboard

 

 5:  Copy all content of index.html to main.php and remove those part which you already have copied and pasted it to respective files. For example remove header, side bar, footer content respectively. Now remove the main content part as highlighted below in screenshot.

Center part of Dashboard

 

6: Now prefix to css and js path this code to make the file path dynamic : 

  1. <?php echo yii\helpers\BaseUrl::base(true); ?>/template/

7: Add Yii2 code whenever necessary. For example I’m going to add some of them.

    a: 

  1. <?php $this->endBody() ?>
before closing the body tag. this will generate debugging bar for you in development environment and other things required to add it to bottom.

    b: 

  1. <?php $this->beginBody() ?>
after opening the body tag.

    c: 

  1. <?php $this->head() ?>
before closing the head tag.

    d: 

  1. <?php $this->beginPage() ?>
before any html content lik doctype tag

    e: 

  1. <?= Breadcrumbs::widget([
  2. 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
  3. ]) ?>
at the place where you like to show breadcrumb

    f: 

  1. <?= Alert::widget() ?>
to show the alert time to time. For example when login is success, or any other alerts.

    g: 

  1. <?= $content ?>
 This is the main part of the layout where your content will appear. This should be placed at the content of step five above.

 

8: You are done. Now type URL in browser, and you’ll see new look of admin dashboard.

 

    

 

Types of KEY in MySQL

 

KEY NAMES KEY DESCRIPTION
PRIMARY KEY Name of the column which uniquely identifies each row of the table with no null value in any row of the table.
UNIQUE KEY Name of the column which uniquely identifies each row of the table, but it can accept a null value for any row of the table.
COMPOSITE KEY The combination of two or more column representing as a unique for each row of the table after merging the columns. It acts like a single column in contest of the key.
SURROGATE KEY A key which has no buisness logic or which have no existance in the real world. for more clarity see NATURAL KEY
FOREIGN KEY Name of the column which have the reference of the other table by having the same value of any column other table.
CANDIDATE KEY Any key which can represent as unique for each row is called CANDIDATE KEY. Hence PRIMARY KEY, UNIQUE KEY and COMPOSITE KEY are a member of CANDIDATE KEY
NATURAL KEY A key which have a real existinence in business logic or have the real value in the world like AADHAR NO in India and SSN NO in USA 
   

Make a chess using PHP

  1. <?php
  2. echo '<table border="1" cellpadding="0" cellspacing="0">';
  3. $black = true;
  4. for ($i = 1; $i <= 8; $i++) {
  5. echo "<tr>";
  6. for ($j = 1; $j <= 8; $j++) {
  7. if ($black == true)
  8. echo "<td style='background: #000;height: 30px;width: 30px;'>&nbsp;</td>";
  9. else
  10. echo "<td style='background: #fff;height: 30px;width: 30px;'>&nbsp;</td>";
  11. $black = !$black;
  12. }
  13. $black = !$black;
  14. echo "</tr>";
  15. }
  16. echo "</table>";
  17. ?>

Output:

chess

 

Find Armstrong Number in PHP

  1. <?php
  2. function is_armstrong($digits)
  3. {
  4. $digits_arr = str_split($digits);
  5. $cube_digit = 0;
  6. foreach ($digits_arr as $digit) {
  7. $cube_digit += find_cube($digit);
  8. }
  9. if ($cube_digit == $digits)
  10. return true;
  11. else
  12. return false;
  13. }
  14.  
  15. function find_cube($no)
  16. {
  17. return $no * $no * $no;
  18. }
  19.  
  20. var_dump(is_armstrong(373));
  21.  
  22. ?>

or

  1. <?php
  2.  
  3. function is_armstrong($number)
  4. {
  5. $num = $number;
  6. $arms = 0;
  7. while ($number > 1) {
  8. $temp = $number % 10;
  9. $arms = $arms + ($temp * $temp * $temp);
  10. $number = $number / 10;
  11. }
  12. if ($num == $arms)
  13. return true;
  14. else
  15. return false;
  16. }
  17.  
  18. var_dump(is_armstrong(163));
  19. ?>