Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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 空白问题magento管理html网格渲染器_Php_Magento_Adminhtml - Fatal编程技术网

Php 空白问题magento管理html网格渲染器

Php 空白问题magento管理html网格渲染器,php,magento,adminhtml,Php,Magento,Adminhtml,我已经重写了app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php 使用app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php &已创建一个渲染器以在网格中显示客户的电子邮件列 这是我的渲染器文件: class Mage_Adminhtml_Block_Renderer_Customer extends Mage_Adminhtml_Block_Widget_Grid_Column_

我已经重写了
app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
使用
app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php
&已创建一个渲染器以在网格中显示客户的电子邮件列

这是我的渲染器文件:

class Mage_Adminhtml_Block_Renderer_Customer extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract 
{

public function render(Varien_Object $row)
{   
    $model = Mage::getModel('customer/customer')->load($row->getCustomerId());

    return  $model->getEmail();

 }

}
&这是我的网格更改(我刚刚添加了一列,我打算让它可以搜索)

我得到了我想要的。但是这个col/有很多前导和尾随的空格 因此,我认为该列无法搜索。 有没有人能建议如何消除这些空白

非常感谢

编辑 几天后,我发现这些空白在网格中很常见&这与可搜索选项无关。 有人能建议如何使用渲染器将已添加到网格中的自定义列设置为可搜索吗??? 谢谢

2编辑 根据《发条奇客》我定制了 我的
\u prepareCollection()
覆盖网格的方法如下

 protected function _prepareCollection()
  { 
    // 'sales/order_collection' is changed from 'sales/order_grid_collection'
    $collection = Mage::getResourceModel('sales/order_collection');  

    $collection->addAttributeToSelect('*')
    ->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')
    ->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left')
    ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
    ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
    ->joinAttribute('billing_fax', 'order_address/fax', 'billing_address_id', null, 'left')
    ->joinAttribute('billing_telephone', 'order_address/telephone', 'billing_address_id', null, '')

    ->addExpressionAttributeToSelect('billing_name',
    'CONCAT({{billing_firstname}}, " ", {{billing_lastname}})',
    array('billing_firstname', 'billing_lastname'))


    ->addExpressionAttributeToSelect('shipping_name',
    'CONCAT({{shipping_firstname}}, " ", {{shipping_lastname}})',
    array('shipping_firstname', 'shipping_lastname'));

    $this->setCollection($collection);
    return parent::_prepareCollection();
}
我还调查过,对于网格,Magento从sales\u flat\u order\u Grid表格中获取数据,而不是从sales\u flat\u order中获取数据,这就是它根据clockworkgeek第一个解决方案报告未知列错误的原因

当前实现的问题是Magento报告错误致命错误:调用未定义的方法Mage\u Sales\u Model\u Mysql4\u Order\u Collection::addExpressionAttributeToSelect()

由于Mage_Sales_Model_Mysql4_Order_集合没有addExpressionAttributeToSelect方法,因此它有addExpressionFieldToSelect方法
现在我需要帮助为addExpressionAttributeToSelect方法编写正确的语法。仅更改方法名称对我没有帮助。我还将文档添加到Grid.php中的
addColumn()
,然后尝试以下操作:

$emailaddress = trim($row->getData($this->getColumn()->getIndex()));
return '<a href="mailto:'.$emailaddress.'">'.$emailaddress.'</a>';
$emailaddress=trim($row->getData($this->getColumn()->getIndex());
返回“”;

这样,您就可以去掉空白,并为管理员用户提供一个可点击的链接:)

为了回答您问题的第二部分,我可以提供这个小技巧

Adminhtml网格列可以采用一个额外的
filter\u condition\u callback
参数,该参数采用标准值。在您的情况下,可以如下方式修改网格:

protected function _prepareColumns() {
    // ...
    $this->addColumn('customer_email', array(
        'header' => Mage::helper('sales')->__('Customer Email'),
        'renderer' => 'adminhtml/renderer_customer',
        'filter_condition_callback' => array($this, 'addCustomerEmailFilter'),
    ));
}

public function addCustomerEmailFilter(Mage_Eav_Model_Entity_Collection_Abstract $collection, Mage_Adminhtml_Block_Widget_Grid_Column $column) {
    $collection->addAttributeToFilter('customer_email', $column->getFilter()->getValue());
}
但是所有这些仍然感觉有点混乱,特别是当属性不是一级列时。对于那些不寻常的情况,您可以在collection类中将输出处理和搜索结合起来

protected function _initSelect() {
    parent::_initSelect();

    // email is existing column, customer_email is generated column
    $this->addExpressionAttributeToSelect(
        'customer_email',
        'TRIM({{email}})',
        array('email')
    );

    return $this;
}

该方法将SQL表达式临时存储为映射字段,以便当网格尝试搜索
customer\u email
时,它会被表达式替换。

首先
trim($row->getData($this->getColumn()->getIndex())
为空,我将其记录并查找。第二,如果我添加了任何html标记,那么空白就会消失。但它不再是可搜索的了。我的基本要求是,它必须像其他COL一样可搜索。此外,
“index”=>“email”
报告了一个错误,
where子句中的未知列“email”
谢谢。如果我的需求团队要求我这样做,至少我知道如何添加发送邮件选项:)谢谢我做了第一步。我在“where子句”中出现了一个未知列“customer\u email”。这是显而易见的,因为订单收集从来没有属性
customer\u email
,它只有
customer\u id
。此外,我查看了Mage\u Sales\u Model\u Mysql4\u Order\u Grid\u Collection类,没有这样的函数
\u initSelect()
。请原谅我没有太多的知识收集和定制他们。但那里只有构造函数。感谢您在我已覆盖的
Mage\u Adminhtml\u Block\u Sales\u Order\u Grid
类的
\u prepareCollection()
中执行此操作?您可以在准备收集时使用
addExpressionAttributeToSelect()
。我想如果你这样做了,就不需要自定义过滤器,这样你就可以忽略我答案的前半部分。我应该在
Mage\u Adminhtml\u Block\u Sales\u Order\u Grid
类的
\u prepareCollection()
或其他地方添加此方法。我重写了grid类,但没有重写model或collection。感谢您的支持是的,请修改
\u prepareCollection()
函数,我相信该函数已经有了
addExpressionAttributeToSelect()
的一些用途。
protected function _initSelect() {
    parent::_initSelect();

    // email is existing column, customer_email is generated column
    $this->addExpressionAttributeToSelect(
        'customer_email',
        'TRIM({{email}})',
        array('email')
    );

    return $this;
}