The Controller

The Controller layer is responsible for organizing and orchestrating the View and the Model. It receives messages from the View layer and triggers Model behavior in order to perform the desired action. Furthermore, it sends messages to the View in order to display Model representations. Both operations are performed thanks to the Application layer, which is responsible for orchestrating, organizing, and encapsulating Domain behavior.

In terms of a web application in PHP, the Controller usually comprehends a set of classes, which, in order to fulfill their purpose, "speak HTTP." In other words, they receive an HTTP request and return an HTTP response:

class PostsController
{
public function updateAction(Request $request)
{
if (
$request->request->has('submit') &&
Validator::validate($request->request->post)
) {
$postService = new PostService();

try {
$postService->createPost(
$request->request->get('title'),
$request->request->get('content')
);

$this->addFlash(
'notice',
'Post has been created successfully!'
);
} catch (Exception $e) {
$this->addFlash(
'error',
'Unable to create the post!'
);
}
}

return $this->render('posts/update-result.html.twig');
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.46.229