![]() |
cutelyst 4.8.0
A C++ Web Framework built on top of Qt, using the simple approach of Catalyst (Perl) framework.
|
Cutelyst Controller base class. More...
#include <Cutelyst/Controller>

Public Member Functions | |
| Controller (QObject *parent=nullptr) | |
| Action * | actionFor (QStringView name) const |
| ActionList | actions () const noexcept |
| QString | ns () const noexcept |
| bool | operator== (const char *className) |
Protected Member Functions | |
| bool | _DISPATCH (Context *c) |
| virtual bool | postFork (Application *app) |
| virtual bool | preFork (Application *app) |
Friends | |
| class | Application |
| class | Dispatcher |
Related Symbols | |
(Note that these are not member symbols.) | |
| #define | C_ATTR(X, Y) |
| #define | C_NAMESPACE(value) |
| #define | CActionFor(str) |
Controllers are where the actions in the Cutelyst framework reside. Each action is represented by a function/method with an attribute to identify what kind of action it is. See the Cutelyst::Dispatcher for more information about how Cutelyst dispatches to actions.
If not explicitely set by C_NAMESPACE() macro, the controller namespace will be generated from the C++ class name and optional C++ namespace name the class is part of. Camel-case class and namespace names like FooBar will be converted into a controller namespace foo/bar, while Foo would be only the foo controller namespace. A class FooBar inside C++ namespace FuBaz would have the controller namespace /fu/baz/foo/bar.
The controller namespace will be prepended to the public path of your controller methods unless you specify a global public path.
A root namespace can be created by setting an empty controller namespace with C_NAMESPACE("").
Public paths are the routes that you can call with your user agent like the web browser. Private paths are internally used and can for example be used to get an URI via Context::uriForAction(). The public path has not to be the same like the private path, but it can be the same.
While the public path is created with the :Path attribute prepended by the controller namespace or from multiple
:Chained actions, the private path will be the function/method name prepended by the controller namespace.
Use the C_ATTR() macro to give hints about methods build like C_ATTR(methodName, options), where options are some of the following:
Indicates the number of expected arguments on a public path. If omitted, an unlimited number of args will be accepted. Can also be set to 0 to expect no arguments.
Arguments are the request url parts behind your public route path. Like if your public path is /foo/bar and you call /foo/bar/fu/baz and there is no other path fitting that and if your /foo/bar path will expect two arguments, the method behind foo/bar would be called with the two arguments 'fu' and 'baz'.
Methods are only exposed to the dispatcher when they have a C_ATTR() macro in front and have a pointer to a Context object as first parameter. If the method should take request arguments it should either have QStringList to take the arguments from Request::arguments() or the expected amount of QString parameters.
There are also three special methods that can be implemented that will be automatically dispatched, they are Begin(), Auto() and End().
Called on the closest namespace match. If the Controller implements Begin(), it’s that action that will be called. Otherwise it will try to match looking at the namespace. So there will be only one Begin() action dispatched.
Begin will be dispached as first action before the Auto() actions and the actual action will be dispatched.
Foo and a FooBar controller with 'foo' and 'foo/bar' namespaces and both implement Auto() and you call an action on the 'foo/bar' namespace, you get Foo->Auto() and FooBar->Auto() called. Definition at line 55 of file controller.h.
|
explicit |
Constructs a Controller object with the given parent.
Definition at line 241 of file controller.cpp.
Referenced by _DISPATCH(), actionFor(), actions(), and ns().
|
virtual |
Definition at line 247 of file controller.cpp.
|
protected |
This is called by the dispatch engine to do the contextual action dispatching. Transversing nearest Begin(), each namespace’s Auto(), the Action method of this controller and nearest End().
Definition at line 378 of file controller.cpp.
References Controller(), Cutelyst::Context::action, and Cutelyst::Action::dispatch().
Referenced by Cutelyst::Dispatcher::dispatch().
| Action * Controller::actionFor | ( | QStringView | name | ) | const |
Returns the Cutelyst::Action object (if any) for a given method name in this class namespace.
You can also use the macro CActionFor to keep the resolved action around.
Definition at line 260 of file controller.cpp.
References Controller().
Referenced by Cutelyst::RoleACL::dispatcherReady().
|
nodiscardnoexcept |
Returns the Cutelyst::ActionList containing all actions which belongs to this controller.
Definition at line 270 of file controller.cpp.
References Controller().
|
nodiscardnoexcept |
This specifies the internal namespace the controller should be bound to. By default the controller is bound to the URI version of the controller name. For instance a controller named 'MyFooBar' will be bound to 'my/foo/bar'. The default Root controller is an example of setting namespace to '' (the null string).
Definition at line 254 of file controller.cpp.
References Controller().
| bool Controller::operator== | ( | const char * | className | ) |
Return TRUE if className is equal to this Controller's name
Definition at line 276 of file controller.cpp.
|
protectedvirtual |
This method is called after the application has registered all controllers.
Reimplement this method if you need to configure internal variable and you need to know for example which configuration options are enabled.
Definition at line 287 of file controller.cpp.
|
protectedvirtual |
This method is called right after Controller has been setup and before application forks and postFork() is called.
Reimplement this method if you need to configure internal variable and you need to know for example which configuration options are enabled.
Definition at line 281 of file controller.cpp.
|
friend |
Definition at line 129 of file controller.h.
|
Sets method attributes Y to method X and marks the method as Q_INVOKABLE.
Definition at line 41 of file controller.h.
|
Explicitely sets the controller namespace to value. Use this in the private part of your controller declaration.
Definition at line 23 of file controller.h.
|
Definition at line 46 of file controller.h.
|
friend |
Definition at line 130 of file controller.h.