PHP chained call

Suppose you have a model class, for example , represent an user table. And you get an uid, how to get the username or other fields of the record which has the uid equals to the parameter?

You may have a class in which a method called GetUser

How to design a request class in PHP

PHP in its nature is not Object Oriented, for example, there are no objects for request and response like Java Servlet did. In Java the HttpServletRequest encapsulate the request information. User access the information through the interface of the class.

We need various information about the request in different place of the application. Directly use $_POST, $_GET, $_COOKIE is fine, but its not a good idea. For example, every time access a field in $_POST, you have to test it with isset.

We need various information about the request in different place of the application. Directly use $_POST, $_GET, $_COOKIE is fine, .

A simple method to implement singleton pattern in PHP

Singleton design pattern is about maintain only one instance of an object in the whole life time of the application.

A common way to implement this pattern is provide a static method in the class that need to be singleton and every time need the instance , just call the static method, the typical name of the method is getInstance without any parameter.

A common way to implement this pattern is provide a static method in the class that need to be singleton and every time need the instance , just call the static method, the typical name of the method is getInstance without .

How to generate a sub tree of a category tree

In last post, we discussed about how to generate a tree output from a category table. In this post, we talk about a similar problem: how to generate a sub tree of the whole tree. The input is an array of category, the final tree will contains these nodes and all their parents but not their children.

Implement auto login in PHP

One of the basic component for every PHP application is the user account system. User can login , logout and register. This post talks about auto login. The user can select "remember me" or "auto login", so after the user login successfully, when the user come back at any later time in a specific period, the user auto login.

Store session data in MongoDB with PHP

MongoDB is scalable document oriented database. This make it a good choice to store of the session information of the users. With MongoDB, your application can grow as the users grows, for example, a Social Network Site.

A special cookie with a name "SID" is used to identify the current session. To start a session , first check the cookie, if there is a cookie named with "SID", then load the session data from MongoDB, if not, create a new session and insert a record that contains session data into database.

A special cookie with a name "SID" is used to identify the current session. To start a session , first check the cookie, if .

Regular expression non-capture in PHP

The non-capture parentheses is a confusing regular expression element. The non-capture operator has a special notation (?:).

Here is an example in PHP:

Advance query in MongoDB with PHP

In last post we demonstrate the basic CRUD in MongoDB. Lets get some advanced query technique.

MongoDB support chained calling, you can filter result by chaining, to select the first 3 recoreds:

CRUD in Mongodb with PHP

and the php extension on windows. Lets do some CRUD operation in PHP script. [Select collection ... In last post we introduced how to install mongodb ... ] => this is content [category] => database ) As you can see Mongodb use an unique id to identify ... ('5188bebf7ab2ad7422000000'); $one = $collection->findone(array('_id' => $id)); print_r($one); The $set tells Mongodb

PHP install PEAR and mongodb on windows

Install PEAR is very easy, just download http://pear.php.net/go-pear.phar and run

Then you can install mongodb like this:

Previous Page 1 ... 3 4 5 Next Page