【问题标题】:How to use Router inside a shell script?如何在 shell 脚本中使用路由器?
【发布时间】:2011-11-17 17:52:11
【问题描述】:

我在app/vendors/shells 中有一个脚本,它通过 cron 定期执行。在该脚本中,我导入了 Router:

class AutosuggestFileShell extends Shell {
    var $uses = array('User','Country','City','Speciality','Alias');

    function main() {
        App::import('Core', 'Router');
        //...

但是脚本没有使用我在routes.php 中定义的路由。例如,我定义了:

Router::connect('/plastic-surgeon/*', array(
    'controller' => 'users', 'action' => 'profile'
));

但在脚本中的这一行:

'path' => Router::url(array(
    'controller' => 'users', 'action' => 'profile', $user['User']['slug']
))

不生成 URL plastic-surgeon/slug - 而是生成 URL users/profile/slug。

Router::url() 在网站的不同位置都能正常工作,例如在视图内生成站点地图。因此我想我需要从 shell 脚本中导入一些东西,或者可能无法从 shell 脚本中加载 routes.php 中包含的数据?

(我使用的是 CakePHP 1.3)

【问题讨论】:

    标签: shell cakephp cakephp-1.3


    【解决方案1】:

    如果你想导入路由试试

    config('routes');
    

    【讨论】:

    • 这对我不起作用。我把它放在任何执行之前内联。
    猜你喜欢
    • 1970-01-01
    • 2020-05-12
    • 1970-01-01
    • 1970-01-01
    • 2013-03-01
    • 2021-01-16
    • 2016-04-20
    • 2010-09-06
    • 2012-07-09
    相关资源
    最近更新 更多