Code Monkey home page Code Monkey logo

Comments (7)

yiiliveext avatar yiiliveext commented on August 25, 2024 1

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.

samdark avatar samdark commented on August 25, 2024

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:

  1. Allow returning strings from handlers (actions).
  2. Provide a shortcut method like createResponseWithBody($string).
  3. ???

from demo.

xepozz avatar xepozz commented on August 25, 2024

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.

samdark avatar samdark commented on August 25, 2024

Returning response directly from render()? Some references would not hurt...

from demo.

samdark avatar samdark commented on August 25, 2024

Yes but that would be:

protected function render(string $view, array $parameters = []): Response

from demo.

yiiliveext avatar yiiliveext commented on August 25, 2024

Yes but that would be:

Of course, I've just forgotten to change after copying.

from demo.

samdark avatar samdark commented on August 25, 2024

Thought more about it. It doesn't sound bad to do it.

from demo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.