skip to Main Content

how do i create a controller inside a folder programmatically using the Spark make command ?
i wrote this code:

    $controllerName = service('request')->getpost('controllerName');
    $controllerPath = service('request')->getpost('controllerPath');
    $controllerFullPath = APPPATH.'Views/'.$controllerPath;
    if (!is_dir($viewFullPath)) {
      mkdir($viewFullPath, 0777, true);
    }

$output = shell_exec('php spark make:controller '.$viewPath.'/'.$viewName);
    print_r($output);die;

the output :
the folder will be created but no controller file.

2

Answers


  1. To create a controller inside a folder using the spark make:controller command in CodeIgniter 4, you need to structure the command correctly. Here’s how you can do it:

    Correct Command Syntax
    Use a backslash () to specify the folder and controller name. For example:

    php spark make:controller Folder/ControllerName
    

    If you want to create a controller named UserController inside a folder Admin:

    php spark make:controller Admin/UserController
    
    Login or Signup to reply.
  2. We can create with three different ways:

    1. Programmatically Generate:

      Use PHP code to dynamically create a file in app/Controllers,
      writing the necessary PHP controller code as a string to the file.

    2. Manually Creating the File:

      Create a PHP file in the app/Controllers directory and write the
      controller class manually, extending CodeIgniterController.

    3. Using Spark CLI:

      Run php spark make:controller Name in the terminal to generate a
      controller named Name in the app/Controllers directory.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search