我正在尝试将一些数据从控制器发送到 phtml以在页面ajax/jason
上显示它们textarea
phtml
在我的控制器中,我有循环
foreach($varlines as $vars =>$variable)
{
$completestatus->setData('comment',$oldcoment.' <br/ > Paid on LEC chq # '.$chqnumber." ".$datepaid." ".$amount)->save();
//because Mage::getSingleton('adminhtml/session')->addSuccess comes after load page
//I need ajax to show the updated order while its running the loop
//and displaying it on phtml
}
<?php
class Ahb_LecRemittance_Adminhtml_LecRemittanceController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout()->renderLayout();
}
public function runremitAction()
{
$post = $this->getRequest()->getPost();
try {
if (empty($post)) {
Mage::getSingleton('adminhtml/session')->addError("Invalid form data.");
Mage::throwException($this->__('Invalid form data.'));
}
if(isset($_FILES['fileinputname']['name']) and (file_exists($_FILES['fileinputname']['tmp_name']))) {
try {
$uploader = new Varien_File_Uploader('fileinputname');
$uploader->setAllowedExtensions(array('csv')); // or 'jpg','jpeg','gif','png' pdf or anything
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir('media')."/tmp". DS ;
$originalfilename=str_replace(' ','',stripslashes($_FILES['fileinputname']['name']));
$originalfilename = trim(preg_replace('/\s*\([^)]*\)/', '', $originalfilename));
$uploader->save($path,$originalfilename );
$data['fileinputname'] = $originalfilename;
//run the file
$path = Mage::getBaseDir('media')."/tmp". DS ;
$filename=$path.$originalfilename;
$file=fopen($filename,"r");
$readchq=false;
$chqnumber="";
if($file!==false){
while(!feof($file))
{
$line=fgets($file);
$varlines=explode(",",$line);
$ordernum=0;
foreach($varlines as $vars =>$variable)
{
$i=0;
if(strpos($variable,"YICP")!==false){ //YICP exist
$ordernum=str_replace('YICP','',$variable);
$amount = str_replace('"','',end($varlines));
$date1=str_replace('"','',$varlines[count($varlines)-2]);
$date2 = str_replace('/', '-', $date1);
$datepaid= date('Y-m-d', strtotime($date2));
$historyid=0;
//get complete status to append its comments
$remittmodel = Mage::getModel('ahb_lecremittance/remittance')
->setOrderid($orderid)
->setAmount($amount)
->setCreated_at($datepaid)
->setChqnum($chqnumber)
->save();*/
$result = array("Order "=>$ordernum,"Amount"=>$amount,"CHQ Num"=>$chqnumber);
//$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
//HERE I need to view the order number added in table while running the foreach loop
//How I do this in ajax
Mage::getSingleton('core/session')->setData('variable1', 'value');
}
}
}
}
fclose($file);
unlink($filename);
Mage::getSingleton('adminhtml/session')->addSuccess($message);
} //end of if fopen
else
Mage::getSingleton('adminhtml/session')->addError("Error: Couldn't open the file ".$filename);
$this->_redirect('*/*');
}catch(Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
$this->_redirect('*/*');
}
}
我的 phtml 文件:
<div class="content-header">
<table cellspacing="0" class="grid-header">
<tr>
<td><h3><?=$this->__('Upload the Monthly Remittance')?></h3></td>
</tr>
<tr>
</tr>
</table>
</div>
<div class="entry-edit">
<form id="edit_form" name="edit_form" method="post" enctype="multipart/form-data" action="<?=$this->getUrl('*/*/runremit')?>">
<input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
<h4 class="icon-head head-edit-form fieldset-legend"><?=$this->__('Remittance file')?></h4>
<?php echo $this->getBlockHtml('formkey') ?>
<fieldset>
<table cellspacing="0" class="form-list">
<tr>
<td><label for="fileinputname">Upload the file </td>
<td><input type="file" name="fileinputname" id="fileinputname" /></td>
<td>
<button onclick="editForm.submit()" class="scalable save" type="button"><span><span>Submit & Run</span></span></button>
</td>
</table>
</fieldset>
</form>
</div>
<input name="test" type="text" value="<?php echo Mage::getSingleton('core/session')->getData('variable1') ?>" />
<script type="text/javascript">
var editForm = new varienForm('edit_form');
</script>