Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to set conditions in Find function of cakephp2.x

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 130
    Comment on it

    In cakephp we might be familiar with the simple find("all") and findById() functions.
    But fetching data with some conditions like we write select query with where condition.

    lets us first look at simple find function

    $this->User->find("all");
    

    This function will fetch all the data from the model.But instead of all if we are required to fetch some data with some condition can be done as :

    $this->User->find('all', 
                       array('conditions'=>array('User.id'=>5)));
    

    In the above we have set one condition in the function but we can set many. Below is the list of other possible conditions we can set:

    1. type : 'first' can be 'all','first', or 'list'. it determines the type of operation to perform.
    2. fields : specifies which fields is to be retrieved.
    3. order : order by conditions. field name must be followed by ASC or DESC.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: