Monday, June 17, 2013

Re: How to edit a view in Cake php

These are the Model, view and controller files. I have to access Customer name.
there are three tables: products, customers and productfamilies.
Have to get customer_id from productfamilies table for corresponding product and
customer_name from customers corresponding to customer_id.

Thanks


On Mon, Jun 17, 2013 at 12:19 PM, Eric Haskins <ehask71@gmail.com> wrote:
Not sure how your getting your $products array

You could use a 

$products = $this->{Model}->find('all',array(
      'joins' => array(          array(              'table' => 'customers',              'alias' => 'CustomerJoin',              'type' => 'INNER',              'conditions' => array(                  'CustomerJoin.customer_id = ProductFamily.customer_id'              )          )      )));
Again I dont know the code before or your table names

Eric

On Monday, June 17, 2013 1:37:38 PM UTC-4, Raks wrote:
Have added a new Column... but m not able to get a column data from other model. I want name from customers table in products view.ctp.

here's the view code:
<?php
$records = array();
foreach ($products as $product){

    $status = ($product['Product']['is_active'] == '1') ? 'Enabled' : 'Disabled';

    $records[] = array(
                        'Product.model' => array('title' => $product['Product']['model'], 'id' => $product['Product']['id']),
                        'Product.part_num' => $product['Product']['part_num'],
                        'ProductFamily.name' => $product['ProductFamily']['name'],
                           // shows customer id.. but want customer name from customers table according to customer id.
  //'Customer.name'=>$product['ProductFamily']['customer_id'],
                        'Product.iron_oem' => ($product['Product']['iron_oem']) ?  'Iron Systems':'Third Party',
                        'ProductType.title' => $product['ProductType']['title'],
                        'Product.is_active' => $status,
                    );
}

$data = json_encode($records);
$ret = "{data:" . $data .",\n";
$ret .= "pageInfo:{totalRowNum:" . $total . "},\n";
$ret .= "recordType : 'array'}";
echo $ret;
?>

On Friday, June 7, 2013 11:40:19 AM UTC-7, Raks wrote:
Hi,
 
I Have a piece of code having view, model and controller . I nee dto make changes to view only not in the database.
So how can i do that. Do I need to edit model and controller as well.
I am new to Cakephp and MVC framework too.
 
Thanks.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to a topic in the Google Groups "CakePHP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cake-php/2KJFo4Ix7Ew/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
-------Ravinder Kaur--------

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: