Search code examples
phpcakephpcakephp-1.3cakephp-2.0

How to print out the value in view file?


i have an array like that, i want to print out it in view file, but it's empty, array is like that

array(
(int) 0 => array(
    'ProductsUserNode' => array(
        'product_user_node_id' => '155',
        'user_node_id' => '53',
        'product_id' => '1',
        'is_active' => '1',
        'expiry' => '0000-00-00',
        'created' => '2013-01-10 10:27:22',
        'modified' => '2013-01-10 10:27:22',
        'created_view' => '10:27 AM, Jan 10,2013',
        'modified_view' => '10:27 AM, Jan 10,2013'
    ),
    'UserNode' => array(
        'user_node_id' => '53',
        'division_id' => '28',
        'role_id' => '4',
        'user_id' => '56',
        'created' => '2013-01-10 10:27:20',
        'created_view' => '10:27 AM, Jan 10,2013'
    ),
    'Product' => array(
        'product_id' => '1',
        'name' => 'Manager',
    )
),

i am using this code in view file

              foreach ($products as $products)
             {
             ?>
            <tr>
                <td>    <?php $products['ProductsUserNode']['product_id']?> </td>
                <td>    <?php $products['Product']['name']?>    </td>
            </tr>
            <?php }?>           

i have also set the variable in controllerlike that,

            $this->set('products',$products);

but it is not working, what's the problem? Thanks in advance


Solution

  • Use the echo keyword to print your variables.

     foreach ($products as $product)
     {
     ?>
     <tr>
          <td>    <?php echo $product['ProductsUserNode']['product_id']?> </td>
          <td>    <?php echo $product['Product']['name']?>    </td>
     </tr>
     <?php }?>