Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 可恢复错误:方法::\uu toString()必须返回字符串值_Php_Magento - Fatal编程技术网

Php 可恢复错误:方法::\uu toString()必须返回字符串值

Php 可恢复错误:方法::\uu toString()必须返回字符串值,php,magento,Php,Magento,当我加载产品页面时,它会在系统日志文件中显示错误,如下所示 2013-03-12T10:28:56+00:00 ERR (3): Recoverable Error: Method SM_Vendors_Model_Mysql4_Vendor_Collection::__toString() must return a string value in C:\xampp\htdocs\magento\app\code\local\SM\Vendors\Block\Adminhtml\Catalo

当我加载产品页面时,它会在系统日志文件中显示错误,如下所示

2013-03-12T10:28:56+00:00 ERR (3): Recoverable Error: Method SM_Vendors_Model_Mysql4_Vendor_Collection::__toString() must return a string value  in C:\xampp\htdocs\magento\app\code\local\SM\Vendors\Block\Adminhtml\Catalog\Product\Render\Vendor.php on line 21
我的代码是

app\code\local\SM\Vendors\Block\Adminhtml\Catalog\Product\Render\vendor.php

class SM_Vendors_Block_Adminhtml_Catalog_Product_Render_Vendor extends Varien_Data_Form_Element_Abstract
{
 public function getElementHtml()
 {
 $vendorCollection = $this->getVendorCollection(); //line#21
 }

 public function getVendorCollection()
 {
  $collection = Mage::getResourceModel('smvendors/vendor_collection')->__toString();
  return $collection;
 }
}
app\code\local\SM\Vendors\Model\Mysql4\Vendor\Collection.php

class SM_Vendors_Model_Mysql4_Vendor_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract 
{
 public function _construct() 
 {
  parent::_construct();
  $this->_init('smvendors/vendor');
 }
 public function __toString()
 {
    return $this->_init('smvendors/vendor');
 }
}
我想解决magento系统日志文件中显示的此类错误。如果您知道,请回复。

确保$this->\u init('smvendors/vendor');返回一个字符串。或者返回另一个字符串,该字符串位于:

public function __toString(){
    return $this->_init('smvendors/vendor');
}

似乎您在代码中使用了不正确的
\uu toString()
方法。
这里这个方法似乎是用来获取集合的,而不是字符串

public function getVendorCollection()
 {
  $collection = Mage::getResourceModel('smvendors/vendor_collection')->__toString();
  return $collection;
 }
这是不正确的,也是一个非常糟糕的想法。
您需要重构代码,否则将永远无法摆脱此警告

该做什么

例如,您可以执行以下操作。。 将
\u-toString
方法重命名为
getCollection
,并将使用
\u-toString
的位置替换为
getCollection

替换,直到日志中的消息不会消失

请在此阅读有关您的问题的更多信息:

下面是固定代码:

class SM_Vendors_Model_Mysql4_Vendor_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract 
{
 public function _construct() 
 {
  parent::_construct();
  $this->_init('smvendors/vendor');
 }
 public function getCollection()
 {
    return $this->_init('smvendors/vendor');
 }

 public function __toString()
 {
    return $this->_init('smvendors/vendor');
 }

}
二等舱

class SM_Vendors_Block_Adminhtml_Catalog_Product_Render_Vendor extends Varien_Data_Form_Element_Abstract
{
 public function getElementHtml()
 {
 $vendorCollection = $this->getVendorCollection(); //line#21
 }

 public function getVendorCollection()
 {
  $collection = Mage::getResourceModel('smvendors/vendor_collection')->getCollection();
  return $collection;
 }
}

尝试
var_dump($this->_init('smvendors/vendor')。这是什么?我已经尝试过了,但对于第21行之后使用的进一步代码,它返回“警告:为foreach()提供的参数无效”。它显示错误,如“2013-03-12T11:55:00+00:00 ERR(3):可恢复错误:SM_Vendors\u Model\u Mysql4\u Vendor\u集合类的对象无法转换为第21行C:\xampp\htdocs\magento\app\code\local\SM\Vendors\Block\Adminhtml\Catalog\Product\Render\Vendor.php中的字符串。请立即尝试(我刚刚还原了\uu toString()方法)。。。管理面板似乎需要它。现在它显示“2013-03-12T12:06:10+00:00错误(3):可恢复的错误:方法SM\U Vendors\U Model\U Mysql4\U Vendor\U Collection::\uu toString()必须在第21行的C:\xampp\htdocs\magento\app\code\local\SM\Vendors\Block\Adminhtml\Catalog\Product\Render\Vendor.php中返回字符串值”。我想清理我的系统日志文件。