user2627106
user2627106

Reputation:

How to get an array of values for the router "segment"?

I use a form with a multiupload. My addAction save information regarding the downloaded files in the database, and obtains an array lastInsrtId() values. If the upload was successful, I need to be redirected to editAction, where a user can see a list of downloaded files and user can edit file attributes such as title, description and alt attribute for images for each downloaded file using this files list. How do I pass an array of values ​​in the route? Here is my code addAction:

// upload success
$fileIds = $this->getContentService()->makeFiles($parent, $data);
return $this->redirect()->toRoute('sc-admin/file/edit', array('ids' => $fileIds));

Here is the definition for a route that should display a list of files for editing:

'edit' => array(
    'type' => 'segment',
    'options' => array(
        'route' => '/edit[/:ids]',
        'defaults' => array(
            'controller' => 'sc-file',
            'action' => 'edit',                
        ),                
    ),                
),

But it generates an error for editAction

rawurlencode() expects parameter 1 to be string, array given

I do not want to use the session whenever the parameters necessary to pass an array of values, because it is a matter solely routing.

Upvotes: 0

Views: 56

Answers (1)

Sam
Sam

Reputation: 16445

Ever seen this url?

http://foo.bar/baz?array(1=>2,3=>4)

Probably not. You got an error message so do as the error message says. This has nothing to do with Zend Framework, this is basic PHP (too many people often forget what's the core...).

array('ids' => serialize($data))

See php:serialize() and php:unserialize()

Upvotes: 1

Related Questions