codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.4k stars 1.9k forks source link

Bug: Generator Command cannot locate the view template. #7405

Closed sammyskills closed 1 year ago

sammyskills commented 1 year ago

PHP Version

7.4

CodeIgniter4 Version

4.3.3

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

apache

Database

No response

What happened?

I created a generator command like so:

php spark make:command TestCommandGenerator --type generator --command make:me-test

And updated the file like so:

public function run(array $params)
{
    $this->component = 'Library';
    $this->directory = 'Libraries';
    $this->template = 'me.tpl.php';

    $this->execute($params);
}

I have the generator template in the directory: app/Commands/Generators/Views/me.tpl.php. But when I try to use the command php spark make:me-test, I get the error message:

Invalid file: "CodeIgniter\Commands\Generators\Views\me.tpl.php"

Steps to Reproduce

  1. Create a new command: php spark make:command TestCommandGenerator --type generator --command make:me-test.
  2. Create the generator template and place it within the app/Commands/Generators/Views folder.
  3. Update the run() method of the TestCommandGenerator.php to contain the name of the view template you created above: $this->template = ''; // name of file here
  4. Run the command php spark make:me-test.

Expected Output

I expect that the view template file would be located within the app namespace instead of CodeIgniter.

Anything else?

No response

datamweb commented 1 year ago

It seems, not creating file me.tpl.php is intentional, this is because even if file me.tpl.php is generated, it should still be defined in app\Config\Generators.php anyway. Otherwise it is not useful.

The following link explains how to create a new command.

sammyskills commented 1 year ago

I'm not even bothered about automatically creating the view template, but locating it when it is added in the $this->template variable.

If it must also be declared in the app/Config/Generators.php file, then the documentation is either misleading or it doesn't contain enough explanations.

kenjis commented 1 year ago

The documentation seems to be insufficient. https://codeigniter4.github.io/CodeIgniter4/cli/cli_generators.html

sammyskills commented 1 year ago

Which is better for the docs?

kenjis commented 1 year ago

It seems adding a section to https://codeigniter4.github.io/CodeIgniter4/cli/cli_generators.html is fine.

sammyskills commented 1 year ago

Submitted a PR #7408