Wednesday, June 2, 2010

How to pass array value from one ctp file to another ctp file

Hi flocks,
I am,  new to cake php  actually i want display one report, in the down i put the link download link for Excel.

For that purpose , i have to display same content for report and  excel, so i was set the query results in one variable rows, using that variable i was displayed the records now same variable i have to use in  In the export_xls.ctp file so, for that purpose i passed variable through query string. so in that time i din't get data, simple its shows array() in address bar.

so how to pass array value form one ctp to ctp in same controller. please help me out.

I wrote code like this.......

MyConroller
----------------------------------------------------------------------------------

<?php
class MyviewsController extends AppController {
 
    var $name = 'Myviews';

    function display() {

        $this->Myview->recursive = 1;
        $data = $this->Myview->find('all');
        $this->set('rows',$data);
    }

    function export_xls($data) {

        $this->set('rows',$data);    
        $this->render('export_xls','export_xls');
 
    }
}
?>




-------------------------------------------------------------------------------------------
ctp files
--------------------------------------------------------------------------------------------
display.ctp

<STYLE type="text/css">
    .tableTd {
           border-width: 0.5pt;
        border: solid;
    }
    .tableTdContent{
        border-width: 0.5pt;
        border: solid;
    }
    #titles{
        font-weight: bolder;
    }
  
</STYLE>
<table>
    <tr>
        <td><b>Export To Excel Sample<b></td>
    </tr>
    <tr>
        <td><b>Date:</b></td>
        <td><?php echo date("F j, Y, g:i a"); ?></td>
    </tr>
    <tr>
        <td><b>Number of Rows:</b></td>
        <td style="text-align:left"><?php echo count($rows);?></td>
    </tr>
    <tr>
        <td></td>
    </tr>
        <tr id="titles">
            <td class="tableTd">Column 1</td>
            <td class="tableTd">Column 2</td>
        </tr>       
        <?php foreach($rows as $row):
            echo '<tr>';
            echo '<td class="tableTdContent">'.$row['Myview']['no'].'</td>';
            echo '<td class="tableTdContent">'.$row['Myview']['name'].'</td>';
            echo '</tr>';
            endforeach;
        ?>
</table>
<br />
<table>
    <tr align="center">

        <td><?php echo $html->image('button_excel_onclick.gif',
                            array('border' => '0',
                                  'url' => array('controller'=> 'myviews',
                                                 'action' => 'export_xls', $rows)));
            ?>     
        </td>
    </tr>
<table>
---------------------------------------------------------------------------------------------
export_xls.ctp
--------------------------------------------------------------------------------------------
<STYLE type="text/css">
    .tableTd {
           border-width: 0.5pt;
        border: solid;
    }
    .tableTdContent{
        border-width: 0.5pt;
        border: solid;
    }
    #titles{
        font-weight: bolder;
    }
  
</STYLE>
<table>
    <tr>
        <td><b>Export To Excel Sample<b></td>
    </tr>
    <tr>
        <td><b>Date:</b></td>
        <td><?php echo date("F j, Y, g:i a"); ?></td>
    </tr>
    <tr>
        <td><b>Number of Rows:</b></td>
        <td style="text-align:left"><?php echo count($rows);?></td>
    </tr>
    <tr>
        <td></td>
    </tr>
        <tr id="titles">
            <td class="tableTd">Column 1</td>
            <td class="tableTd">Column 2</td>
        </tr>       
        <?php foreach($rows as $row):
            echo '<tr>';
            echo '<td class="tableTdContent">'.$row['Myview']['no'].'</td>';
            echo '<td class="tableTdContent">'.$row['Myview']['name'].'</td>';
            echo '</tr>';
            endforeach;
        ?>
</table>
---------------------------------------------------------------------------

please any one can help me out......!

thanks in advance...!

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
 
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: