Kohana — Command Line

后端 未结 6 1718
情话喂你
情话喂你 2021-02-14 02:54

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/emai         


        
相关标签:
6条回答
  • 2021-02-14 03:33

    And Kohana2 is just php index.php controller/method/param1/param2/etc

    Kohana was built to run on the CLI as well as web.

    0 讨论(0)
  • 2021-02-14 03:34

    I had a similar issue

    Did you or anyone add the SERVER_NAME to the index.php file?

    If so either remove the code outside the index.php (and or bootstrap) OR you can wrap it it in a

    if (PHP_SAPI === 'cli') 
    { 
       // ... 
    }  else {
     //....
    }
    
    0 讨论(0)
  • 2021-02-14 03:44

    For Kohana 3, check out these docs and source.

    0 讨论(0)
  • 2021-02-14 03:49

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

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

    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:

    For kohana 2:

    php index.php controller/method/var1/var2
    

    Kohana 3

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

    Edit: 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
    0 讨论(0)
  • After looking into Kohana3 source code, I found that it has support for cli (system/classes/kohana/cli.php). You can pass 3 options (uri, method, get, post). So:-

    $ php index.php --uri="items/list"

    would call the list method in Controller_Items.

    0 讨论(0)
  • 2021-02-14 03:53

    If you are using Kohana 3 then you can run it from the terminal.

    Example

    php index.php --uri=controller/action
    

    Options

    • --uri
    • --method
    • --get
    • --post
    0 讨论(0)
提交回复
热议问题