Search code examples
javascriptphpextjszend-framework

Passing an array within a controller and action from Zend Framework to a location.href extjs


I'm doing a project with a backend made with zend framework and a front-end made with extjs.

My problem is that after a user gridpanel is loaded and i press the edit icon to edit a user, I cannot used location.href to redirect to the edit section because I don't know how to send the info of the user ID in the way that zend framework controller recognize it.

this is the line of code i have

location.href = "< ? php echo $this->url(array('controller'=>'index','action'=>'edit','id'=>$id)) ?>"; 

this line of code is inside a actionColumn in the php way. I have a function with extjs to take the id of the user that i want to edit, but i don't know how to store it in the $id php variable


Solution

  • There seems to be a misconception. With Javascript, you cannot pass variables to php. In ExtJs even more, everything is done in the client and you have to load the data asynchronously through ajax.

    Now in ExtJs, it would make little sense to load a new page from the server to edit a row in a grid. If you've done things correctly, this grid is bound to a store, that contains the users data. After you edited it, you save the changes to the server.

    Now to answer your question : in the handler of the action column, the current record is passed to the function. See doc

    handler: function (view, row, column, item, e, record) {
        $id = record.getId()
    } 
    

    $id is now the user's id.