Welcome Guest, Not a member yet? Register   Sign In
Why spark adding ResponseInterface to controller?
#1

(This post was last modified: 02-19-2024, 04:22 AM by Muzikant.)

Why spark adding ResponseInterface to controller as it is not directly used in the scope?

php spark make:controller Test
PHP Code:
<?php

namespace App\Controllers;

use 
App\Controllers\BaseController;
use 
CodeIgniter\HTTP\ResponseInterface// unused in the scope

class Test extends BaseController
{
    public function index()
    {
        //
    }

Reply
#2

Run
Code:
php spark make:controller --restful
Reply
#3

Thank you, I appreciate it. But it is not an answer on my question. What is the reason behind adding it by default?
Reply
#4

It just means that the output is not optimized for each controller.

Normal controllers do not need ResponseInterace, but a dev may use it.
Besides, unused use statements are automatically removed by php-cs-fixer,
so devs don't need to worry about them.
Reply
#5

(This post was last modified: 02-20-2024, 09:27 PM by luckmoshy.)

@Muzikant You don't have to be a fan of other developers and other developers who are interested in using ResponseInterface also won't use likewise
so bear in mind that the framework lesson basement should have basic tools to help facilitate some tasks to a developer so that you don't need to worry otherwise you may remove either by manual or php-cs-fixer as @kenjis says
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#6

(This post was last modified: 02-21-2024, 04:38 AM by Muzikant.)

Kenjis, thank you. I did not know about PHP-CS-Fixer. I am still learning. I will look at it. So it was added because it can be used? Why this one and not other ones?
Reply
#7

"use CodeIgniter\HTTP\ResponseInterface" was added because REST controller uses it.

Also, the return types of controller action methods are only string or ResponseInterface.
Reply
#8

CodeIgniter DevKit provides useful tools for development.
https://github.com/codeigniter4/devkit
Reply
#9

(This post was last modified: 02-22-2024, 01:51 AM by Muzikant.)

Now I have a little insight into it. I was wondering why it was added. I will look at DevKit too. Thank you and good luck.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB