Sep 24, 2013

PHP isset() vs empty() vs is_null()

PHP has different functions which can be used to test the value of a variable. Three useful functions for this are isset(), empty() and is_null(). All these function return a boolean value. If these functions are not used in correct way they can cause unexpected results.
isset() and empty() are often viewed as functions that are opposite, however this is not always true. In this post I will explain the differences between these functions.

Jun 26, 2013

Tạo user trong CentOS

#useradd -m -d /var/www/html/user1 user1
#passwd user1
#chown -R user1:apache /var/www/html/user1
# chmod 755 -R /var/www/html/user1

Jun 14, 2013

Cập nhật time trong CentOS

#yum install ntp
#ntpdate time.windows.com

Kiểu DateTime trong PHP

Một số thủ thuật để xử lý DateTime trong PHP: lấy ngày tháng hiện tại, so sánh ngày, tính thời gian chênh lệch giữa 2 ngày.

May 29, 2013

Expanding CakePHP multistep forms with dynamic fields and serialized data

As a sequel to the post about multistep forms with CakePHP, I’d like to add a little bit of complexity to that sample. This time we’ll add some dynamically generated fields and, in general, serialized data.

Write less code: merge Save and Edit in CakePHP

In most cases writing less code gives the developer a series of advantages: it’s easier to maintain and extend, easier to read and easier to debug! In this post I’m going to suggest a little CakePHP tip that in the long run will save you a lot of coding.
Some develepers already implement this method, but I think it deserves much wider usage: I’m talking about merging model save and edit in a single controller method.

Multistep forms in CakePHP 2.2.2

One of the features I really love about PHP frameworks is form management. Coding forms in plain PHP can easily become a pain if not well planned out. Multistep forms take this complexity even further, especially when you care about user experience.
In this tutorial you’ll be amazed by how much little code can manage a whole full featured multistep form when taking advantage of CakePHP powerful classes. We’ll build the form in only 60 lines of controller code.

May 25, 2013

CsvExport Behavior for CakePHP 2

This behavior is the exact opposite of the CsvImport behavior included in the Utils plugin from CakeDC. This Behavior will end on github but for now, here is the source code and instructions on how to use the Behavior.

Enable CSV Import for all controllers/models in a CakePHP 2.x project

CakePHP LogoI often use phpMyAdmin to import csv data into projects I am building, this can be tedious as phpMyAdmin requires the number of fields and field order to match exactly for the csv import to work.
This frustration prompted me to explore the Utils plugin by CakeDC which contains a CsvImport behavior. I wanted this functionality for all of my controllers/models during the development process. Import functionality will eventually end up under the admin interface of my project. If you use admin routing and would like the import functionality only available through an admin url simply change the method name below to admin_import().

May 14, 2013

Date Picker trong CakePHP 2.x với Bootstrap

Mục tiêu:


Chọn ngày format dd-mm-yyyy sau đó save vào CSDL trường kiểu date.