Magento 1.7无法发送标题;标头已发送 [英] Magento 1.7 Cannot send headers; headers already sent in

查看:78
本文介绍了Magento 1.7无法发送标题;标头已发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已解决 我在乔纳森·休西(Jonathan Hussey)的帮助下解决了这个问题 我更改了这一行:

SOLVED I solved this issue with Jonathan Hussey help I changed this line:

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

为此:

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

问题
我创建了自定义模块,该模块向带有其他文本字段的管理产品页面添加了标签页. 当我尝试保存该产品时,出现此错误:

Problem
I created custom module which added tab to admin product page with additional text field. When I try save this product I get this error:

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中创建了此错误:

I saw that this error created in 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();

您是否有解决办法?

编辑 管理模板标签文件的内容:

EDIT content of admin template tab file:

<?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


Debug backtrace after line $mModel->getCollection()->load($mId)->getData(); from Observer.php

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

推荐答案

使用集合时,如果要记录或输出该集合的SQL,则仅应将参数传递给->load().如果您不希望集合返回所有项目,则可以使用->getSelect()从集合中拉出选择对象,并使用

When working with collections you should only pass arguments to ->load() if you want the SQL for that collection to be logged or output. If you don't want the collection to return all items you can pull the select object from the collection with ->getSelect() and filter with standard Zend methods this way.

如果您回溯收集命令,您会看到,因为传递了一个参数,它回显了收集SQL.

If you trace back your collection command you will see because you pass an argument it echo's out the collection SQL.

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

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

Have a look at lib/Varien/Data/Collection/Db.php as per the error message and find the load() method. You will see that it accepts two aguments, $printQuery and $logQuery, you have passed an argument to $printQuery. A few lines down in the method you see:

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

查看printLogQuery()方法,您将看到作为错误消息传递为 $ printQuery 参数的任何内容触发错误消息,均会触发693行上的回显:

Looking at the printLogQuery() method you will see that anything passed as the $printQuery argument which evaluates to true triggers the echo on line 693 as per the error message:

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

这是在您的情况下发送标头的方法.从->load()删除参数或传递 false ,它应该可以解决您的问题.

This is what is sending headers in your case. Remove the argument from ->load() or pass false and it should fix your problem.

这篇关于Magento 1.7无法发送标题;标头已发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆