Json Zend窗体和Ext.grid.Panel

Json Zend窗体和Ext.grid.Panel,json,extjs,extjs4,zend-form,zend-framework,Json,Extjs,Extjs4,Zend Form,Zend Framework,我在一家使用表格html/JS界面的公司工作。这些都是本地生成的(对上帝来说是真实的),每个单元格都附带了查询事件。对于旧的用法,它们是合适的,但是行和单元格之间的交互在客户端变得更加复杂。具体来说,他们需要服务器端和客户端验证 为了促进这一点,我报告给的开发人员非常喜欢Zend_表单,他们坚持认为,要使用像ExtJS这样的框架,他们不希望必须编写两次后端和前端代码(请忽略,如果都是自行开发的,他们无论如何都必须这样做) 因此,考虑到这一点,我正试图利用杠杆来创造。为此,我需要使用decorat

我在一家使用表格html/JS界面的公司工作。这些都是本地生成的(对上帝来说是真实的),每个单元格都附带了查询事件。对于旧的用法,它们是合适的,但是行和单元格之间的交互在客户端变得更加复杂。具体来说,他们需要服务器端和客户端验证

为了促进这一点,我报告给的开发人员非常喜欢Zend_表单,他们坚持认为,要使用像ExtJS这样的框架,他们不希望必须编写两次后端和前端代码(请忽略,如果都是自行开发的,他们无论如何都必须这样做)

因此,考虑到这一点,我正试图利用杠杆来创造。为此,我需要使用decorators导出一个数组(然后使用ViewHelper将其json),或者直接呈现一个json字符串

因此,这将类似于:

$dateElement = new Zend_Form_Element_Text('startDate', array(
    'label' => 'Start Date',
    'validators' => array(
        new Zend_Validate_Date()
    )
));

echo (string)$dateElement;
将输出:

{ text: 'Start Date',  dataIndex:'startDate', xtype:'datecolumn'}
或者(显然不是使用字符串转换,但可能是使用
->toArray()
或其他方法):

我想如果我能把它带到这个阶段,我就能从中得到我所需要的


这里有没有人尝试过做类似的事情(获得JSON/XML/其他标记输出,而不是使用Decorators从Zend_表单获取HTML),或者他们是否可以向我指出任何资源?

我想我有一个解决方案

制作与此类似的装饰器:

class My_Form_JSON_Decorator extends Zend_Form_Decorator_Abstract{

    protected $xtype;
    protected $dataIndex;

    public function __construct($dataIndex,$xtype){
        $this->xtype=$xtype;
        $this->dataIndex=$dataIndex;
    }

    public function render($content){
        $element=$this->getElement();
        $label=$element->getLabel
        //if you need errors here too do the same with $element->getMessages();
        return 'array ("text"=>"'.$label.'","dataIndex"=>"'.$this->dataIndex.'","datecolumn"=>"'.$this->xtype.'")';
    }
}
$dateElement = new Zend_Form_Element_Text('startDate', array(
    'label' => 'Start Date',
    'validators' => array(
        new Zend_Validate_Date()
)
$dateElement->setDecorators(array(
    new My_Form_JSON_Decorator("startDate","datecolumn");
));
然后,在表单上,使用类似以下内容:

class My_Form_JSON_Decorator extends Zend_Form_Decorator_Abstract{

    protected $xtype;
    protected $dataIndex;

    public function __construct($dataIndex,$xtype){
        $this->xtype=$xtype;
        $this->dataIndex=$dataIndex;
    }

    public function render($content){
        $element=$this->getElement();
        $label=$element->getLabel
        //if you need errors here too do the same with $element->getMessages();
        return 'array ("text"=>"'.$label.'","dataIndex"=>"'.$this->dataIndex.'","datecolumn"=>"'.$this->xtype.'")';
    }
}
$dateElement = new Zend_Form_Element_Text('startDate', array(
    'label' => 'Start Date',
    'validators' => array(
        new Zend_Validate_Date()
)
$dateElement->setDecorators(array(
    new My_Form_JSON_Decorator("startDate","datecolumn");
));
最后,在视图上,您应该有:

{
    Date: <?php echo $this->form->startDate; ?>,
}
{
日期:,
}
我没有尝试上面的代码,但是,我使用了一个类似的代码,我曾经在需要更改窗体的装饰器时使用过

这不可能完全正确,但我认为它向你展示了一种方法


干得好=)

我想我有一个解决办法

制作与此类似的装饰器:

class My_Form_JSON_Decorator extends Zend_Form_Decorator_Abstract{

    protected $xtype;
    protected $dataIndex;

    public function __construct($dataIndex,$xtype){
        $this->xtype=$xtype;
        $this->dataIndex=$dataIndex;
    }

    public function render($content){
        $element=$this->getElement();
        $label=$element->getLabel
        //if you need errors here too do the same with $element->getMessages();
        return 'array ("text"=>"'.$label.'","dataIndex"=>"'.$this->dataIndex.'","datecolumn"=>"'.$this->xtype.'")';
    }
}
$dateElement = new Zend_Form_Element_Text('startDate', array(
    'label' => 'Start Date',
    'validators' => array(
        new Zend_Validate_Date()
)
$dateElement->setDecorators(array(
    new My_Form_JSON_Decorator("startDate","datecolumn");
));
然后,在表单上,使用类似以下内容:

class My_Form_JSON_Decorator extends Zend_Form_Decorator_Abstract{

    protected $xtype;
    protected $dataIndex;

    public function __construct($dataIndex,$xtype){
        $this->xtype=$xtype;
        $this->dataIndex=$dataIndex;
    }

    public function render($content){
        $element=$this->getElement();
        $label=$element->getLabel
        //if you need errors here too do the same with $element->getMessages();
        return 'array ("text"=>"'.$label.'","dataIndex"=>"'.$this->dataIndex.'","datecolumn"=>"'.$this->xtype.'")';
    }
}
$dateElement = new Zend_Form_Element_Text('startDate', array(
    'label' => 'Start Date',
    'validators' => array(
        new Zend_Validate_Date()
)
$dateElement->setDecorators(array(
    new My_Form_JSON_Decorator("startDate","datecolumn");
));
最后,在视图上,您应该有:

{
    Date: <?php echo $this->form->startDate; ?>,
}
{
日期:,
}
我没有尝试上面的代码,但是,我使用了一个类似的代码,我曾经在需要更改窗体的装饰器时使用过

这不可能完全正确,但我认为它向你展示了一种方法


很好=)

您想要的是打印一个字段,并将其名称打印为JSON或XML,而不是HTML?我问这个问题是因为我从未使用过ExtJS,但是,如果这是您想要的,我想我有一部分解决方案。。。你能举一个例子说明你想从Decorators输出什么吗?我希望能够将整个元素表示为一个JSON,就像在HTML中呈现“表示”元素一样,减去验证。这是这里的关键,我想将验证从后端传递到javascript,这样我就可以方便用户进行js验证,也可以在PHP上再次验证,因为出于安全原因,我不能相信$u请求是干净的。你想要的是打印一个字段,并将其名称作为JSON或XML,而不是HTML?我问这个问题是因为我从未使用过ExtJS,但是,如果这是您想要的,我想我有一部分解决方案。。。你能举一个例子说明你想从Decorators输出什么吗?我希望能够将整个元素表示为一个JSON,就像在HTML中呈现“表示”元素一样,减去验证。这是这里的关键,我想将验证从后端传递到javascript,这样我就可以进行用户方便的js验证,也可以在PHP上再次验证,因为出于安全原因,我不能相信$u请求是干净的。代码工作得好吗?还是有错误?如果有错误,请让我知道如何编辑答案,并将其更正=)代码运行良好吗?还是有错误?如果有错误,请让我知道如何编辑答案并更正它们=)