Laravel – Specified key was too long


Edit app/Providers/AppServiceProvider.php

Add this line under namespace declaration

use Illuminate\Support\Facades\Schema;

Add this line on boot function

Schema::defaultStringLength(191);

Advertisements

Yii : CGridView – Create Custom Column


I have a field which contains one character to represent project status (eg: F=Finished, S=Start, P=Pending, etc)

By default, CGridView will display one character value, but we want CGridView to display its description taken from other table, this is what I did:

First, create a component, let’s name it MyComponent. You can do it by create MyComponent.php and save it in component folder, I write something like this:

<?php
class MyComponent extends CApplicationComponent 
{
 public function getProjectStatus($statusCode)
 { 
 $sql = "SELECT STATUS_CODE,
 DESCRIPTION
 FROM REF_PROJECT_STATUS WHERE STATUS_CODE='$statusCode'";

 $rs = Yii::app()->db->createCommand($sql)->queryAll();

 $data = array();

 foreach($rs as $item){

 $statusCode = $item['STATUS_CODE'];
 $description = $item['DESCRIPTION'];

 $data[$statusCode] = $description;
 }
 
 return $data[$statusCode]; 
 } 
}

This way, you can call the function like this
Yii::app()->mycomponent->getProjectStatus($statusCode)

Then, replace the field name in your views (admin.php) with something like this

array('header' => 'Project Status', 'value' => 'Yii::app()->mycomponent->getProjectStatus($data->PROJECT_STATUS)'),

Some people suggest the function should be static

Yii version: 1.1.10

Adminer – Set Number of Rows to Display


I’ve ever wrote how to set this on PhpMyAdmin, now I want to do it on Adminer. I want Adminer to show 200 records when I select a table. I’ve try it using Adminer v4.1.0 and v4.2.0 both for MySQL english only.

I just search the string “selectLimitProcess(){” with no quote off course and then replace its default number from 50 to 200, you can use any number you want.

PHP – Enable FileInfo in Windows


1. Add php_fileinfo.dll to the list of enabled extensions 

extension=php_fileinfo.dll

2. Download GNU file package for windows
get it from here: http://gnuwin32.sourceforge.net/downlinks/file-bin-zip.php

Extract the folder from the archive called shared\file which contains 4 magic files (magic, magic.mgc, magic.mime, magic.mime.mgc).

3. Place these 4 files in a known place

4. Add system enviroment variable MAGIC that points to the file called magic. For example if you placed magic files in folder called magic in c:\php that means that the propper path is c:\php\magic\magic

5. If you use IIS restart it and fileinfo is ready for use

5a. If you use apache you will have to restart operating system for the service to acknowledge MAGIC env. variable.

 

source:

http://php.net/manual/en/fileinfo.installation.php