New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change behaviour of render
method
#52
Comments
render
objectrender
method
View component is not aware of request-response. Its job is rendering templates. I don't think it's a good idea to couple it like suggested. Still, I agree that it looks a bit cumbersome to create response like that (while it makes perfect sense if redirect or sending headers is involved). Possible solutions:
|
If you want to render and collect result to string you can use Moreover, such a template is familiar to all PHP developers (at least), because all frameworks provide such a convenient interface. |
Returning response directly from |
I think @xepozz means something like this //abstract class Controller
protected function render(string $view, array $parameters = []): string
{
$response = $this->responseFactory->createResponse();
$content = $this->view->render($view, $parameters, $this);
$response->getBody()->write($this->renderContent($content));
return $response;
} |
Yes but that would be: protected function render(string $view, array $parameters = []): Response |
Of course, I've just forgotten to change after copying. |
Thought more about it. It doesn't sound bad to do it. |
What steps will reproduce the problem?
Using
render
function to render content of view file looks too hard.Instead of return the result of
render
function we should to create response before and write data after.Let's delegate creating the
Response
object torender
function.What is the expected result?
User controllers will be more simpler and cleaner
What do you get instead?
The text was updated successfully, but these errors were encountered: