Skip to content

Controller return output instead of echo view #179

Description

@timothymarois
public function index()
{
    return view('welcome_message');
}

instead of echo view('welcome_message');

To have the controller "return" it's output would go with modern standards. Using echo within controller is bad practice, though the CI4 isn't complete and it was just an example with the Home.php (welcome), however I wanted to make a note of that.

Returning a view should display that view, returning an "array" should automatically encode that into JSON output (Like Laravel). A controller acts as an API, so should make predictions to how it would be used and save work for developers. Of course there could be configurations to change any built-in functionality. Unless I am working on php and html mixed pages, using echo in classes is worrisome.

Not a major issue, just a request to clean up functionality. (of course echo would always be allowed based on php, but a return would seem cleaner on the output, and prevent other code below from loaded if I've already returned my view)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions