将控制器中的数组和动作从 Zend Framework 传递到 location.href extjs
Passing an array within a controller and action from Zend Framework to a location.href extjs
我正在做一个项目,后端使用 zend 框架,前端使用 extjs。
我的问题是,在加载用户网格面板并按编辑图标编辑用户后,我无法使用 location.href
重定向到编辑部分,因为我不知道如何发送以 zend 框架控制器识别方式显示的用户 ID 信息。
这是我的代码行
location.href = "< ? php echo $this->url(array('controller'=>'index','action'=>'edit','id'=>$id)) ?>";
这行代码以 php 的方式位于 actionColumn 中。我有一个带有 extjs 的函数来获取我要编辑的用户的 ID,但我不知道如何将它存储在 $id
php 变量
中
好像是误会了。使用 Javascript,您不能将变量传递给 php。在ExtJs中更是如此,一切都在客户端完成,你必须通过ajax异步加载数据。
现在在 ExtJs 中,从服务器加载新页面来编辑网格中的行没有什么意义。如果您做对了,这个网格将绑定到一个包含用户数据的商店。编辑后,将更改保存到服务器。
现在回答您的问题:在操作列的处理程序中,当前记录被传递给函数。请参阅文档
handler: function (view, row, column, item, e, record) {
$id = record.getId()
}
$id 现在是用户的 ID。
感谢洛伦兹的回答。是的,我明白你的意思,JS 在客户端执行。是的,数据在商店中,该数据是使用 ajax 代理从一些 url 加载的,具有基本身份验证 header。我以这种方式捕获 id 值,
<script>
var store = Ext.create('Ext.data.Store', {
//model: 'Contactos',
//pageSize: 25,
autoLoad: true,
proxy: {
type: 'ajax',
url: 'https://app.alegra.com/api/v1/contacts/',
method: 'GET',
reader: {
type: 'json',
rootProperty: 'data',
id: 'id'
},
headers: {
Accept : 'application/json',
Authorization: 'Basic something'
}
}
});
Ext.create('Ext.grid.Panel',{
title: 'Contactos',
id: 'cat_categoriesGrid',
store: store,
// bbar: pagingToolbar,
columns: [
{ text: '#', dataIndex: 'id', width: 35 },
{ text: 'Nombre', dataIndex: 'name', width: 210},
{text: 'Identificacion', dataIndex: 'identification',width: 210},
{text: 'Telefono 1', dataIndex: 'phonePrimary',width: 210},
{text: 'Observaciones', dataIndex:'observations',width: 210},
{
text: 'Acciones',
width: 210,
xtype: 'actioncolumn',
items: [{
icon: '<?php echo $this->baseUrl('image/page_edit.png');?>', // Use a URL in the icon config
tooltip: 'Edit',
handler: function(grid, rowIndex, colIndex, a, b, c) {
var rec = grid.getStore().getAt(rowIndex);
var id = rec.get('id');
location.href = "<?php echo $this->url(array('controller'=>'index','action'=>'edit','id'=>$id)) ?>";
}
},
{
icon: '<?php echo $this->baseUrl('image/delete.png');?>', // Use a URL in the icon config
tooltip: 'Delete',
handler: function(grid, rowIndex, colIndex, a, b, c) {
}
},
]
}
],
width: 1100,
style: 'margin:0 auto;margin-top:15px;',
enableColLock:false,
//selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
renderTo: Ext.getBody()
});
在 extJS 中,是的,编辑部分应该让我进入一个新页面并加载我将编辑的数据,但我不知道如何做?我有一个 ZEND 控制器,但我不知道如何使用 extjs 访问它,我的想法是在处理程序中回显上面的行,这样我就可以获得该新页面,但我不能将“var id”放入该回显中。因此,如果不能这样做,我如何从 extjs 访问 Zend 框架控制器?
这是我在 Zend F 上的控制器
class IndexController extends Zend_Controller_Action
{
public function init()
{
}
public function editAction()
{
// action body
$id = $this->getRequest()->getParam('id');
$client = new Zend_Http_Client('https://app.alegra.com/api/v1/contacts/'.$id);
$client->setAuth('admin', 'password');
//se solicita un request con los parametros que se estan pasando en client
$a = $client->request('GET');
$b = strstr($a, '{');
$json_alegra = substr($b,0, -5);
//Se pasa de json a array
$phpNative = Zend_Json::decode($json_alegra); //$phpNative = json_decode($json_alegra, true);
//$this->view->response = $a;
$this->view->form = new Application_Form_Alegraform();
//usamos populate para llenar el formulario con el array $phpNative
//las variables del array deben cooncordar con las del form
$this->view->form->populate($phpNative);
$this->view->form->setAction($this->view->
url(array('controller'=>'index','action'=>'update','id'=>$id)));
}
我正在做一个项目,后端使用 zend 框架,前端使用 extjs。
我的问题是,在加载用户网格面板并按编辑图标编辑用户后,我无法使用 location.href
重定向到编辑部分,因为我不知道如何发送以 zend 框架控制器识别方式显示的用户 ID 信息。
这是我的代码行
location.href = "< ? php echo $this->url(array('controller'=>'index','action'=>'edit','id'=>$id)) ?>";
这行代码以 php 的方式位于 actionColumn 中。我有一个带有 extjs 的函数来获取我要编辑的用户的 ID,但我不知道如何将它存储在 $id
php 变量
好像是误会了。使用 Javascript,您不能将变量传递给 php。在ExtJs中更是如此,一切都在客户端完成,你必须通过ajax异步加载数据。
现在在 ExtJs 中,从服务器加载新页面来编辑网格中的行没有什么意义。如果您做对了,这个网格将绑定到一个包含用户数据的商店。编辑后,将更改保存到服务器。
现在回答您的问题:在操作列的处理程序中,当前记录被传递给函数。请参阅文档
handler: function (view, row, column, item, e, record) {
$id = record.getId()
}
$id 现在是用户的 ID。
感谢洛伦兹的回答。是的,我明白你的意思,JS 在客户端执行。是的,数据在商店中,该数据是使用 ajax 代理从一些 url 加载的,具有基本身份验证 header。我以这种方式捕获 id 值,
<script>
var store = Ext.create('Ext.data.Store', {
//model: 'Contactos',
//pageSize: 25,
autoLoad: true,
proxy: {
type: 'ajax',
url: 'https://app.alegra.com/api/v1/contacts/',
method: 'GET',
reader: {
type: 'json',
rootProperty: 'data',
id: 'id'
},
headers: {
Accept : 'application/json',
Authorization: 'Basic something'
}
}
});
Ext.create('Ext.grid.Panel',{
title: 'Contactos',
id: 'cat_categoriesGrid',
store: store,
// bbar: pagingToolbar,
columns: [
{ text: '#', dataIndex: 'id', width: 35 },
{ text: 'Nombre', dataIndex: 'name', width: 210},
{text: 'Identificacion', dataIndex: 'identification',width: 210},
{text: 'Telefono 1', dataIndex: 'phonePrimary',width: 210},
{text: 'Observaciones', dataIndex:'observations',width: 210},
{
text: 'Acciones',
width: 210,
xtype: 'actioncolumn',
items: [{
icon: '<?php echo $this->baseUrl('image/page_edit.png');?>', // Use a URL in the icon config
tooltip: 'Edit',
handler: function(grid, rowIndex, colIndex, a, b, c) {
var rec = grid.getStore().getAt(rowIndex);
var id = rec.get('id');
location.href = "<?php echo $this->url(array('controller'=>'index','action'=>'edit','id'=>$id)) ?>";
}
},
{
icon: '<?php echo $this->baseUrl('image/delete.png');?>', // Use a URL in the icon config
tooltip: 'Delete',
handler: function(grid, rowIndex, colIndex, a, b, c) {
}
},
]
}
],
width: 1100,
style: 'margin:0 auto;margin-top:15px;',
enableColLock:false,
//selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
renderTo: Ext.getBody()
});
在 extJS 中,是的,编辑部分应该让我进入一个新页面并加载我将编辑的数据,但我不知道如何做?我有一个 ZEND 控制器,但我不知道如何使用 extjs 访问它,我的想法是在处理程序中回显上面的行,这样我就可以获得该新页面,但我不能将“var id”放入该回显中。因此,如果不能这样做,我如何从 extjs 访问 Zend 框架控制器?
这是我在 Zend F 上的控制器
class IndexController extends Zend_Controller_Action
{
public function init()
{
}
public function editAction()
{
// action body
$id = $this->getRequest()->getParam('id');
$client = new Zend_Http_Client('https://app.alegra.com/api/v1/contacts/'.$id);
$client->setAuth('admin', 'password');
//se solicita un request con los parametros que se estan pasando en client
$a = $client->request('GET');
$b = strstr($a, '{');
$json_alegra = substr($b,0, -5);
//Se pasa de json a array
$phpNative = Zend_Json::decode($json_alegra); //$phpNative = json_decode($json_alegra, true);
//$this->view->response = $a;
$this->view->form = new Application_Form_Alegraform();
//usamos populate para llenar el formulario con el array $phpNative
//las variables del array deben cooncordar con las del form
$this->view->form->populate($phpNative);
$this->view->form->setAction($this->view->
url(array('controller'=>'index','action'=>'update','id'=>$id)));
}