February 26 2014

Yii accessRules filter access in controllers for user roles.

Tagged Under :

Yii
I had install Rights module inside my application. The Rights module itself wouldn’t auto integrate with the controller.

So I need to integrate myself, at each of the controller we need to add 2 extra function they are:
public function filters() {
  return array(
    'accessControl', 
  );
}
and
public function accessRules() {
  return array(
    array('allow',
          'action' => array('Index'),
          'users' => array('@'),
    ),
  );
}

February 24 2014

ASP.net MSSQL connection test

Tagged Under : ,

asp.net
I am making a little code to test the functionality server with MSSQL Database connection. The test code was develop with asp.net C#.

If the script successful connect with MSSQL Database it will display message like below:
TESTS COMPLETED SUCCESSFULLY!.
Else, it will display
TESTS FAILED!

Server script:

February 21 2014

How to enable details error information in IIS and ASP.NET

Tagged Under :

asp.net
By default, IIS and ASP.NET hide detailed error information to prevent revealing sensitive information about your web application.
Sometimes we need to see error details (think shared hosting) to debug our coding.

To display the error message. Add these entries to your web.config file to disable generic errors:

February 19 2014

PHP Convert a String to Variable

Tagged Under :

php
Have 2 methods to do it.

Method 1:
echo eval('return $'. $string . ';');

And another method as below:
$counter = 1;
$button1 = "Hello PHP";
$printbutton = ${'button' . $counter};

echo $printbutton
The Method 2 example will print out Hello PHP

February 19 2014

Install php5 on Miscrosoft IIS

Tagged Under :

php
Installing PHP itself is quite straightforward; the difficulty lies in configuring IIS to use it! There are a number of programs contained within the standard Win 32 distribution, for example it contains two versions of the PHP interpreter that we can use with IIS. The first is a DLL (Dynamic Link Library) that contains an ISAPI module for IIS. This module will run as a persistent interpreter in IIS, one that does not need to be called externally, so in theory should provide the best performance.

In reality, I have found the ISAPI module to be unstable with PHP 5 and IIS on Windows, often causing access violations. These issues will most likely be resolved in time, and may be by the time that you are reading this.

The second version, a standard C executable, is the one that we will be using. This runs under IIS as an external CGI (Common Gateway Interface) call, similar to the way Perl/CGI works, so as a result is not as quick as the ISAPI module, but it is very stable. In the trade-off between speed and stability, we should always favour stability for a live production server.

Installing Steps
-Create a folder called PHP on the C drive root
-Unzip the contents of the zip file you downloaded for PHP 5 into C:\PHP
-In C:\PHP, rename php.ini-dist to php.ini 
-You may want to add C:\PHP onto the system path variable, as you did for MySQL in the previous section
That’s it! Now onto configuring PHP 5.

February 13 2014

ASP.net MVC Model add a new field

Tagged Under : ,

asp.net
After add extra field inside the Model. I get an error message when I run the application.

The error message as below:
The model backing the 'MyContext' context has changed since the database was created.
It was because the Model was different with Database field. And now, you need rebuild the Database structure again.

The solution is:
1. Open Package Manager Console from Tools -> Libraray Package Manager -> Package Manager Console
2. PM> Enable-Migrations -ContextTypeName <TheDatabaseName>
3. Set AutomaticMigrationsEnabled=true, from Migrations folder of Configuration file
4. PM> Add-Migration InitialCreate
5. PM> Update-Database
Now try run the application again. it will work fine and updated to the new Model.

Or you can use another way to solve the problem.

February 13 2014

Cannot attach the file as database

Tagged Under : ,

asp.net
Because I did delete the DB file and now I get an error message when I run the application. I expected it was the DB file was deleted by me and it didn’t help me rebuild the DB.

To solve this issue, we need stop and delete the Database with follwing step:
1. Open Package Manager Console from Tools -> Libraray Package Manager -> Package Manager Console
2. Stop local DB with command: PM > sqllocaldb.exe stop v11.0
3. and then delete it PM > sqllocaldb.exe delete v11.0
Now try run the application again. it will work fine again.

January 21 2014

SQL Server Date Formats

Tagged Under : ,

mssql
How to format datetime value or column into a specific date format. Is the most frequently asked question by the newbie. Below table is summary of the different date formats that come from SQL Server with the CONVERT function.

Please note that the output of these date formats are VARCHAR data type, not DATETIME data type. With this in mind, any date comparisons performed after the DATETIME value has been formatted are using the VARCHAR value of the date and time and not its original DATETIME value.

January 15 2014

Jquery plugin tablesorter filter match how to

Tagged Under :

jquery
Jquery tablesorter is a powerful plugin for table sort and filter. It help me completed a lot of stuff.

But I found a problem, when I want filter by exact match results, the default filter function cannot do this. And I try add “filter-match” classes to the “th” header cells. Unfortunately the results return still same.

The Solution:
To filter by exact match, you may need modify or add “filter_functions” at the “widgetOptions“. The example:

January 11 2014

IE custom cursor

Tagged Under :

css3
I found that quite a lot of people omit Internet Explorer browser, when they are doing the CSS.

For example like the custom cursor. In Firefox, Safari and Chrome, it can display property when you use PNG image format, but it not for IE. that’s the reason why custom cursor not working on IE browser.