Magento 1.7无法发送标头;已发送的标头

时间:2013-03-27 22:04:13

标签: php magento zend-framework magento-1.7

解决 我用Jonathan Hussey的帮助解决了这个问题 我更改了这一行:

$mModel->getCollection()->load($mId)->getData();

为此:

$mModel->getCollection()->addFieldToFilter('met_id',$Id)->getSelect();

问题
我创建了自定义模块,它将标签添加到带有附加文本字段的管理产品页面 当我尝试保存此产品时,我收到此错误:

a:5:{i:0;s:140:"Cannot send headers; headers already sent in /home/nano/domains/mydomain/public_html/gw/lib/Varien/Data/Collection/Db.php, line 693";i:1;s:1630:"#0 /home/nano/domains/mydomain/public_html/gw/lib/Zend/Controller/Response/Abstract.php(148): Zend_Controller_Response_Abstract->canSendHeaders(true)...

我在Observer.php中看到了这个错误:

$mId = $collection['m_id'];         
$mModel->getCollection()->load($mId)->getData(); <-- this line give an error

$data['met_id'] = $mId;
$data['product_id'] = $product->getId();
$data['metf1'] = $this->_getRequest()->getPost('f1');
$mModel->setData($data);
$mModel->save();

你有什么想法解决这个问题吗?

修改 管理模板标签文件的内容:

<?php
$product = Mage::registry('current_product');
$mItem = Mage::getModel('mmodel/mmodel')->getCollection()->
addFilter('product_id',$product->getId())->getFirstItem();

echo '<div class="input-field">
 <label for="f1">File</label>
 <input type="text" class="input-text" name="f1" id="f1" value='.$mItem['f1'].' />
</div>';


从Observer.php

$mModel->getCollection()->load($mId)->getData();后调试回溯
SELECT `main_table`.* FROM `mmodel` AS `main_table`
    Debug Backtrace:
    File    Line    Function
    /home/nano/domains/mydomain/public_html/gw/app/code/local/GW/MModel/Model/Observer.php  42  printDebugBacktrace
    /home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Model/App.php    1338    saveProductTabData
    /home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Model/App.php    1317    _callObserverMethod
    /home/nano/domains/mydomain/public_html/gw/app/Mage.php 468 dispatchEvent
    /home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Model/Abstract.php   466 dispatchEvent
    /home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Catalog/Model/Product.php 548 _afterSave
    /home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Model/Abstract.php   319 _afterSave
    /home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php   714 save
    /home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Controller/Varien/Action.php 419 saveAction
    /home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php    250 dispatch
    /home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Controller/Varien/Front.php  176 match
    /home/nano/domains/mydomain/public_html/gw/app/code/core/Mage/Core/Model/App.php    354 dispatch
    /home/nano/domains/mydomain/public_html/gw/app/Mage.php 704 run
    /home/nano/domains/mydomain/public_html/gw/index.php    87  run

1 个答案:

答案 0 :(得分:4)

使用集合时,如果要记录或输出该集合的SQL,则只应将参数传递给->load()。如果您不希望集合返回所有项目,您可以使用->getSelect()从集合中提取选择对象,并以standard Zend methods方式过滤。

如果你追溯你的收集命令,你会看到,因为你传递了一个参数,它回显了集合SQL。

$mModel->getCollection()->load($mId)->getData();

根据错误消息查看lib/Varien/Data/Collection/Db.php并找到load()方法。您将看到它接受两个aguments, $ printQuery $ logQuery ,您已将参数传递给 $ printQuery 。您看到的方法中有几行:

$this->printLogQuery($printQuery, $logQuery);

查看printLogQuery()方法,您会看到以 $ printQuery 参数传递的任何内容都会根据错误消息触发第693行的回显:

echo is_null($sql) ? $this->getSelect()->__toString() : $sql;

这就是你的情况下发送标题的内容。从->load()中移除参数或传递 false ,它应该可以解决您的问题。