> For the complete documentation index, see [llms.txt](https://doc.kaliphp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.kaliphp.com/shell.md).

# 脚本执行

KaliPHP 框架除了提供HTTP的请求处理以外，同时还提供了一套完整的脚本执行逻辑，基本上和HTTP请求保持一致

执行入口为一样是根目录下的`index.php`文件，用户可以通过命令行执行`php index.php {router} {param}`方式调用

其中`router`为脚本路由，`param`为执行参数，可缺省或多个参数

### 脚本路由

路由跟http请求模式基本保持一致，只需要改变传参方式即可，改为`--ct={control} --ac={action}`的形式，`{control}`和`{action}`都可以缺省，默认为`index`

例如：`--ct=index --ac=test`就会执行`index`中的`test`方法，而`--ct=demo`则会执行`demo`中的`index`方法

```
// app/index.php
namespace control;
class ctl_index extends ctl_base
{
    // _init方法会先被执行
    public static function _init()
    {
    }

    //默认路由index
    public function index()
    {
        echo __method__."\n";
    }
}
```

### 脚本参数

框架提供了变量化的参数传递方式，用法与http模式保持一致

例如：终端执行`php index.php --ct=test --ac=demo --id=23 --name="test"`，结果如下：

```
namespace app;
class ctl_test extends ctl_base
{
    public function demo()
    {
        //23
        echo req::item('id', 0, 'int');
        //demo
        echo req::item('name');
        //default
        echo req::item('prm', 'default');
    }
}
```
