What data can be returned form the controller?

DigPix

Joined: 2004-04-07
Posts: 31
Posted: Wed, 2004-04-28 09:57

Hi all,

i would like to know what data can be returned from the controllers in g2 and how it is evaluated. I did not find much information about this in the source code and collecting the information from the modules is quite tedious.

So it would be great if we could collect some information about this.

The controller returns an array (here: $results) with information about what view to use, and can also give some information to the view.
What i assume so far is the following:

$results['error']
contains flags which signal that a certain error has occured. It is used like this:
$results['error'][] = 'form[error][userName][missing]'
This information is given to the template (question: on redirect and delegate?), which can check the flag via "isset($form.error.userName.missing)"

$results['status']
contains information about the status which resulted from the last operation. Stored as associative array and used like this:
$results['status']['modifiedUser'] = $user->getUserName();
In the template it can be accessed as $status.modifiedUser
(question: template var is only present after a redirect, not after a delegate, right?)

$results['delegate']
contains information about the view to use.
$result['delegate']['view'] is the view itself
$result['delegate']['subView'] optionally is a subview to use
(question: are there any more options to the delegate array?)

OR (only one of (delegate|redirect) can be used)

$results['redirect']
forces a http-redirect to the given view.
$result['redirect']['view'] is the view itself
$result['redirect']['subView'] optionally is a subview to use
The controller is determined by the view. Optionally it can be set explicitly by $result['redirect']['controller']='...' (which is possible in g2 urls generally)
Any other key-value-pairs in the redirect array are set as query variables in the redirect-url.
(question: are there any more options to the redirect-array?)

Am i right so far? Are there any more options to control the application flow which i have not noticed yet?
I think i saw an entry 'return' somewhere without knowing what it does...

It would be great to collect all the information about these arrays. This will certainly be a big help for other developers starting with g2.

Thanks!
Sebastian

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7985
Posted: Thu, 2004-04-29 18:40

You're right -- this is something that should be documented much better. I added much better documentation to the handleRequest() method in GalleryController. It'll show up in the PHPDoc in a couple of hours. Let me know if there's more to add there.

 
DigPix

Joined: 2004-04-07
Posts: 31
Posted: Mon, 2004-05-03 08:24

Thanks for adding this to phpdoc!

You have the following line in the documentation:
status => array('key' => 'value') view => array('error code', 'error code', ...)
I guess you meant "error" instead of "view", right?

It's good to have this in the phpdoc. I think a more detailed version like i wrote in the beginning would be helpful too, perhaps somewhere in the developers documentation?

Sebastian

 
DigPix

Joined: 2004-04-07
Posts: 31
Posted: Mon, 2004-05-03 20:19

I noticed that sometimes there is an additional entry
$result['return'] = 1
Can somebody explain what this means?

Sebastian

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7985
Posted: Tue, 2004-05-04 07:27

The PHPDoc wasn't refreshing itself, so you were looking at the old version. Check back again and you'll see there's a much more detailed accounting of the return values which should answer your last two posts.

 
DigPix

Joined: 2004-04-07
Posts: 31
Posted: Tue, 2004-05-04 18:30

Thanks Bharat,
now thats a detailed doc and indeed answers all my questions... :-))

Small sidenote: there's an </pre> on the end of the new doc which i guess shouldn't be there.

Sebastian

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7985
Posted: Thu, 2004-05-06 09:22
DigPix wrote:
Small sidenote: there's an </pre> on the end of the new doc which i guess shouldn't be there.

Fixed!