CakePHP:仅将控制器方法限制为shell?
在我的很多 Cake 应用程序中,我都有通过 cron 和 cake 控制台调用的 shell,我想知道是否可以以“私有”方式限制这些方法,以便它们只能由控制台调用?例如,假设我的 shell 中有这个:
$this->requestAction(array('controller' => 'reviews', 'action' => 'generateReports'));
我如何将“generateReports”操作限制为“仅 shell”方法?因为我还可以通过以下方式在浏览器中调用该方法: http://site.url/reviews/generateReports
尽管这对于调试可能很有用,但在生产环境中可能会很危险。
如果我将该方法设为私有,即 _generateReports,那么 shell 将不允许执行它。有什么想法吗?我觉得应该有一个简单的解决方案来解决这个问题,但我还没有找到一个或类似的问题。谢谢!
In a lot of my Cake apps I have shells which are invoked via cron and the cake console, and I am wondering if I can restrict these methods in a "private" manner so that they can be ONLY invoked by the console? For example, let's say I have this in my shell:
$this->requestAction(array('controller' => 'reviews', 'action' => 'generateReports'));
How could I restrict the "generateReports" action to be a "shell only" method? Because I could also invoke the method in my browser by going to:http://site.url/reviews/generateReports
And as useful as this may be for debugging it could be dangerous in a production environment.
If I make the method private, i.e. _generateReports, then the shell will not be allowed to execute it. Any ideas? I feel like there should be an easy solution to this but I haven't been able to find one, or a similar question posted. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的操作仅由服务器执行,那么为什么要在可访问 Web 的控制器内构建该操作呢?
如果您只希望 CakeShell 运行该方法,则该操作只能创建为 CakeTask。
If your action is only to be executed by the server, then why build out the action inside of a web accessible controller?
If you wish for only the CakeShell to run that method then the action should only be created as a CakeTask.