Kohana-命令行 [英] Kohana -- Command Line

查看:91
本文介绍了Kohana-命令行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的Web应用程序中伪造"一个进程(通过SMTP发送电子邮件),并且该应用程序基于Kohana构建.

I'm trying to "faux-fork" a process (an email being sent via SMTP) in my web application, and the application is built on Kohana.

    $command = 'test/email';
    exec('php index.php '.$command.' > /dev/null/ &', $errors, $response);

我遇到了错误-

Notice: Undefined index: SERVER_NAME

当我查看Kohana的index.php文件时,我看到它正在寻找一个名为SERVER_NAME的变量,但是我猜想它即将变为NULL,因为Kohana无法检测到该值并在运行前对其进行设置.

When I look into Kohana's index.php file, I see that it is looking for a variable named SERVER_NAME, but I guess it is coming up NULL because Kohana couldn't detect this value and set it prior to run.

有什么想法如何让Kohana通过命令行运行?

Any ideas how to get Kohana to run via command line?

推荐答案

据我所知,由于其引导方法,您无法直接在命令行中运行kohana文件.

As far as I know you can't run the kohana files directly in command line because of its bootstrap methods.

您可以做两件事: 将所有命令(如函数)导出到kohana之外,然后独立运行.

You could do 2 things: export all command like functions outside kohana and run them independently.

您可以做的另一件事是通过kohana主文件夹中的index.php运行它,同时传递$ controller和$ method变量,使其最终到达代码所在的正确对象:

Something else you could do is running it trough the index.php located in the kohana main folder while passing the $controller, $method variables to it so it ends up at the right object where your code is located:

对于kohana 2:

For kohana 2:

php index.php controller/method/var1/var2

Kohana 3

php index.php --uri=controller/method/var1/var2

修改: Kohana从3.3版开始有一个出色的CLI任务运行程序,作为官方模块.对于3.2版,它仍然是一个非官方的模块.我建议您使用这些命令,因为它们在从CLI运行时会提供很多其他选项:

Kohana has a great CLI task runner from version 3.3 onward as official module. For version 3.2 it's still an unofficial module. I suggest you use these because they give a lot of extra options on running from CLI:

  • Kohana 3.2 - https://github.com/Zeelot/kohana-minion
  • Kohana 3.3 - https://github.com/kohana/minion

这篇关于Kohana-命令行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆