Comments (7)
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;
}
from demo.
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:
- Allow returning strings from handlers (actions).
- Provide a shortcut method like createResponseWithBody($string).
- ???
from demo.
If you want to render and collect result to string you can use $this->getView()->render(...);
Controller::render()
is only wrapper over $view->render
. I do not see any problems in returning Response
Moreover, such a template is familiar to all PHP developers (at least), because all frameworks provide such a convenient interface.
from demo.
Returning response directly from render()
? Some references would not hurt...
from demo.
Yes but that would be:
protected function render(string $view, array $parameters = []): Response
from demo.
Yes but that would be:
Of course, I've just forgotten to change after copying.
from demo.
Thought more about it. It doesn't sound bad to do it.
from demo.
Related Issues (20)
- Minor Issue: Dependency Checker - The following 6 unknown symbols were found HOT 5
- No definition or class found or resolvable for "Yiisoft\Translator\MessageReaderInterface" while building "Yiisoft\Translator\MessageReaderInterface". HOT 1
- add fixture error HOT 1
- Yiisoft\Di\NotFoundException No definition or class found or resolvable for "Yiisoft\Validator\RuleHandlerContainer" while building "Yiisoft\Validator\RuleHandlerContainer". HOT 1
- could some body release a zip file with the installed vendor folder? HOT 1
- PHP Compile Error — Yiisoft\ErrorHandler\Exception\ErrorException Declaration of Yiisoft\Yii\Cycle\Data\Reader\EntityReader::withLimit(int $limit): Yiisoft\Yii\Cycle\Data\Reader\EntityReader must be compatible with Yiisoft\Data\Reader\ReadableDataInterface::withLimit(int $limit): Composer\Autoload\ClassLoader HOT 3
- PHP Fatal Error — Yiisoft\ErrorHandler\Exception\ErrorException Class Yiisoft\Yii\Cycle\Data\Reader\EntityReader contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Yiisoft\Data\Reader\FilterableDataInterface::withFilterHandlers) HOT 6
- update links
- Composer install error HOT 1
- PHP Fatal Error — Yiisoft\ErrorHandler\Exception\ErrorException Class App\Widget\FlashMessage contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Yiisoft\Widget\Widget::render) HOT 3
- it seem the url parameter can be removed? HOT 2
- Fix tests after the latest `Locale` middleware changes HOT 2
- Move language groups to params, configure translator HOT 1
- Registration doesn't work with SQLite
- Incorrect attribute in `blog/src/User/Controller/UserController.php` HOT 5
- Fix SSL autorenewing
- Bad URI prefix — Yiisoft\Yii\Middleware\Exception\BadUriPrefixException HOT 4
- Yiisoft\Assets\Exception\InvalidConfigException The sourcePath to be published does not exist: C:\wamp64\www\demo\blog/node_modules/bootstrap/dist HOT 3
- CurrentRequest is valid HOT 13
- How can the variable $error be used to reflect errors? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from demo.