Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Discussion on retrieving and set the data in cakePHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 211
    Comment on it

    Hi Reader's,
    Welcome to FindNerd, today we are going to discuss retrieving and set the data in cakePHP.

    If you want to retrieve the data from the database in your CakePHP web application. So in CakePHP, there is an inbuilt function to get the data from the database. find() is a multifunctional  function of all model data-retrieval function which is used under the controller.

     Find() is used for fetching the data from the database according to the given condition. All condition are given below:

    1:-First
    2:-Count
    3:-All
    4:-List

     

    let explain one by one.

     

    1. First- It is used for getting the first matched result.

    we can see below query

    <?php 
        $Userdetail = $this->User->find('first', array(
              'order' => array('User.created' => 'desc')
          ));
    
    ?>

     

    2:-Count- This is used for finding the integer value. It count the number of data that satisfy the condition.

    we can see below query for better understanding:

    <?php
        $TotalRecord = $this->User->find('count');
     ?>

     

    3:-All- It is used for finding all the data when the condition satisfy.

    we can see below query:

    <?php 
          $AllRecoed = $this->User->find('all', array(
          'conditions' => array('User.status' => 'pending')
        ));
    ?>
    

     

    4:-List- This is helpful where we want a list and it is used to get an indexed array like we want the list of states or country or city.

    <?php 
          $StateName = $this->State->find('list', array('fields' => array('State.name'),'order' => array('State.name' => 'ASC')));
    
    ?>

    If we want to set the retrieved data in view then we can easily set it in our view.

    Suppose we can set the data for state then our code will like below:

    <?php
           $this->set('states', $StateName);
     ?>
    

     

 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: