Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php codeigniter的自定义cli_Php_Linux_Node.js_Codeigniter_Command Line Interface - Fatal编程技术网

Php codeigniter的自定义cli

Php codeigniter的自定义cli,php,linux,node.js,codeigniter,command-line-interface,Php,Linux,Node.js,Codeigniter,Command Line Interface,(我不知道如何用语言表达) 我使用的是linux debian, 我对拉威尔有点了解, 我想为codeigniter项目创建类似artisan的命令 我想做喜欢的事 mycommand create controller <controller name> mycommand创建控制器 您可以使用codeigniter和。创建一个只接受cli请求的控制器,您可以在视图目录中创建模板,在其中可以指定新控制器的外观 控制器示例: <?php if (!defined('BASEP

(我不知道如何用语言表达) 我使用的是linux debian, 我对拉威尔有点了解, 我想为codeigniter项目创建类似artisan的命令 我想做喜欢的事

mycommand create controller <controller name>
mycommand创建控制器

您可以使用codeigniter和。创建一个只接受cli请求的控制器,您可以在视图目录中创建模板,在其中可以指定新控制器的外观

控制器示例:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class create extends CI_Controller {

    public function __construct()
    {
        parent::__construct();

        if( ! $this->input->is_cli_request())
        {
            show_404();
        }
    }

    public function controller($controller_name = '', $dir = '')
    {
        if (empty($controller_name))
        {
            echo 'Please enter controller name!';
        }
        else
        {
            if ( ! empty($dir))
            {
                $dir = '/' . trim($dir, '/');
            }

            $fullpath = APPPATH . 'controllers' . $dir . '/' . $controller_name . EXT;

            if (file_exists($fullpath))
            {
                echo 'Filename exists.';
            }
            else
            {
                if ( ! is_dir(dirname($fullpath)) )
                {
                    mkdir(dirname($fullpath), 0777, true) or die("Unable to create a directory!");
                }

                $data = array('controller_name' => $controller_name);

                $template = $this->load->view('template/controller', $data, true);

                $file = fopen($fullpath, "w") or die("Unable to create a file!");

                fwrite($file, html_entity_decode($template));

                echo $controller_name . ' created.';
            }
        }
    }

}
这将在控制器中创建admin.php,但是,如果您想将其放在目录中,只需为目录添加另一个参数即可

php index.php cli create controller admin backend

同样,这将创建文件“controller/backend/admin.php”

您可以使用codeigniter和。创建一个只接受cli请求的控制器,您可以在视图目录中创建模板,在其中可以指定新控制器的外观

控制器示例:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class create extends CI_Controller {

    public function __construct()
    {
        parent::__construct();

        if( ! $this->input->is_cli_request())
        {
            show_404();
        }
    }

    public function controller($controller_name = '', $dir = '')
    {
        if (empty($controller_name))
        {
            echo 'Please enter controller name!';
        }
        else
        {
            if ( ! empty($dir))
            {
                $dir = '/' . trim($dir, '/');
            }

            $fullpath = APPPATH . 'controllers' . $dir . '/' . $controller_name . EXT;

            if (file_exists($fullpath))
            {
                echo 'Filename exists.';
            }
            else
            {
                if ( ! is_dir(dirname($fullpath)) )
                {
                    mkdir(dirname($fullpath), 0777, true) or die("Unable to create a directory!");
                }

                $data = array('controller_name' => $controller_name);

                $template = $this->load->view('template/controller', $data, true);

                $file = fopen($fullpath, "w") or die("Unable to create a file!");

                fwrite($file, html_entity_decode($template));

                echo $controller_name . ' created.';
            }
        }
    }

}
这将在控制器中创建admin.php,但是,如果您想将其放在目录中,只需为目录添加另一个参数即可

php index.php cli create controller admin backend

同样,这将创建文件“controller/backend/admin.php”

您可以使用codeigniter和。创建一个只接受cli请求的控制器,您可以在视图目录中创建模板,在其中可以指定新控制器的外观

控制器示例:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class create extends CI_Controller {

    public function __construct()
    {
        parent::__construct();

        if( ! $this->input->is_cli_request())
        {
            show_404();
        }
    }

    public function controller($controller_name = '', $dir = '')
    {
        if (empty($controller_name))
        {
            echo 'Please enter controller name!';
        }
        else
        {
            if ( ! empty($dir))
            {
                $dir = '/' . trim($dir, '/');
            }

            $fullpath = APPPATH . 'controllers' . $dir . '/' . $controller_name . EXT;

            if (file_exists($fullpath))
            {
                echo 'Filename exists.';
            }
            else
            {
                if ( ! is_dir(dirname($fullpath)) )
                {
                    mkdir(dirname($fullpath), 0777, true) or die("Unable to create a directory!");
                }

                $data = array('controller_name' => $controller_name);

                $template = $this->load->view('template/controller', $data, true);

                $file = fopen($fullpath, "w") or die("Unable to create a file!");

                fwrite($file, html_entity_decode($template));

                echo $controller_name . ' created.';
            }
        }
    }

}
这将在控制器中创建admin.php,但是,如果您想将其放在目录中,只需为目录添加另一个参数即可

php index.php cli create controller admin backend

同样,这将创建文件“controller/backend/admin.php”

您可以使用codeigniter和。创建一个只接受cli请求的控制器,您可以在视图目录中创建模板,在其中可以指定新控制器的外观

控制器示例:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class create extends CI_Controller {

    public function __construct()
    {
        parent::__construct();

        if( ! $this->input->is_cli_request())
        {
            show_404();
        }
    }

    public function controller($controller_name = '', $dir = '')
    {
        if (empty($controller_name))
        {
            echo 'Please enter controller name!';
        }
        else
        {
            if ( ! empty($dir))
            {
                $dir = '/' . trim($dir, '/');
            }

            $fullpath = APPPATH . 'controllers' . $dir . '/' . $controller_name . EXT;

            if (file_exists($fullpath))
            {
                echo 'Filename exists.';
            }
            else
            {
                if ( ! is_dir(dirname($fullpath)) )
                {
                    mkdir(dirname($fullpath), 0777, true) or die("Unable to create a directory!");
                }

                $data = array('controller_name' => $controller_name);

                $template = $this->load->view('template/controller', $data, true);

                $file = fopen($fullpath, "w") or die("Unable to create a file!");

                fwrite($file, html_entity_decode($template));

                echo $controller_name . ' created.';
            }
        }
    }

}
这将在控制器中创建admin.php,但是,如果您想将其放在目录中,只需为目录添加另一个参数即可

php index.php cli create controller admin backend

同样,这将创建这个文件“controller/backend/admin.php”

查看Phil Sturgeon通过CodeIgniter:Check out-CodeIgniter命令行工具处理CLI输入/输出的绝妙软件包,如Laravel Artisan,它可以使用命令快速创建控制器模型视图。请查看Phil Sturgeon通过CodeIgniter:Check out-CodeIgniter命令行工具处理CLI输入/输出的绝妙软件包,如Laravel Artisan,它可以使用命令快速创建控制器模型视图。请查看Phil Sturgeon通过CodeIgniter:Check out-CodeIgniter命令行工具处理CLI输入/输出的绝妙软件包,如Laravel Artisan,它可以使用命令在中快速创建控制器模型视图。查看Phil Sturgeon通过CodeIgniter处理CLI输入/输出的绝妙软件包:签出-CodeIgniter命令行工具,如Laravel Artisan,它可以使用命令在中快速创建控制器模型视图。