If you’re using the controller class, you’re writing the content of a method. Although you can just write your logic and not return anything, you can also return some values to instruct the framework of some special cases.

(this is experimental for 3.0.4 and currently only for the viaAJAX() method)
Note: from 3.2.1 the same applies to regular controllers

There are basically 4 regular cases and a special case :

- if you return nothing (i.e. null), the output is handled the usual way, in other words the whole page is built from the current theme template (it’s the common case for direct requests or ajax request who expect a complete page).

- if you return false (the exact boolean value), the framework will consider something went wrong and will display an error messages. By default this message warns the user that the controller couldn’t be found, but you can customize the message by setting an array in $this->core->haltController.

- if you return true (the exact boolean value), the framework will consider you have handled the output yourself, so won’t output anything on its own (just set an empty template and flush the buffer).

- in the last case, the data you return will be used as the controller content. Be sure to provide only a string, which will be displayed instead of the whole page. That means the theme template will not be used, an empty template will be used instead.

- the special case is when the request explicitly asked for JSON data (by setting the “HTTP_X_REQUESTED_TYPE” http header to “json”), whatever data you return will be json-encoded and returned to the browser.

Currently any other value will throw an exception.

Réaction

Était-ce utile?

Oui Non
Vous avez indiqué que ce sujet ne vous a pas été utile ...
Pouvez-vous SVP laisser un commentaire nous disant pourquoi? Merci!
Merci pour vos commentaires.

Laissez votre avis sur ce sujet.

Valider