I have a problem with Cakephp.
after created xml views, I want to use xml from that page to use in another page.
//public function gettransaction() in controller
$this->loadModel('Cardstatement'); //Since it's not a default model. so I have to load it.
$uid = $this->Auth->user('id');
if(isset($uid) && $uid==='1') //if uid of user is 1, will get all data from database. if not, they can only see data that have the same uid as them.
$this->set('transaction',$this->Cardstatement->find('all'));
else
$this->set('transaction',$this->Cardstatement->findAllByUid($uid));
$this->set('_serialize', array('transaction')); //serialize data to make xml views.
This code works fine. it can show xml views when I access http://localhost/cakephp/users/gettransaction.xml
//public function transaction() in controller
$this->rss_item = Xml::toArray(Xml::build('http://localhost/cakephp/users/gettransaction.xml'));
$this->set('data',$this->rss_item['response']['transaction']);
//transaction.ctp in View folder
<h1 style="font-weight: bold; font-size: 2em;">List of Users</h1>
<table>
<tr>
<th>Date</th>
<th>Seller Number</th>
<th>Product</th>
<th>Price</th>
<th>Number</th>
<th>User id</th>
<th>Transaction Number</th>
</tr>
foreach($data as $temp_item){ ?>
<tr>
<td><?php echo $temp_item['Cardstatement']['date']; ?></td>
<td><?php echo $temp_item['Cardstatement']['sellerno']; ?></td>
<td><?php echo $temp_item['Cardstatement']['product']; ?></td>
<td><?php echo $temp_item['Cardstatement']['price']; ?></td>
<td><?php echo $temp_item['Cardstatement']['number']; ?></td>
<td><?php echo $temp_item['Cardstatement']['uid']; ?></td>
<td><?php echo $temp_item['Cardstatement']['transno']; ?></td>
</tr>
<?php } ?>
</table>
I found out that when using the code above. It's always show error that "String could not be parsed as XML". but when I change directory and use a normal xml file. it's work normally.
I've searched over the internet and found nothing relative with my question.
It took me a days and still can't figure out what's wrong and how should I solve it.
No comments:
Post a Comment