Cron Job在Laravel 4 [英] A Cron Job in Laravel 4

查看:220
本文介绍了Cron Job在Laravel 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个Cron工作来执行一个Scraper到网站,并发送电子邮件的信息,我做了一个控制器,但我设置命令运行该文件

I need a Cron job for execute a Scraper to a Website and send emails with the information, I made a Controller to do that, but when I set up the command to run that file


php app/controllers/ScraperController.php 

我收到此错误


PHP致命错误:在
中找不到类'BaseController'/var/www/U-Scraper/app/controllers/ScraperController.php on line 2

PHP Fatal error: Class 'BaseController' not found in /var/www/U-Scraper/app/controllers/ScraperController.php on line 2

事情是,当我设置一个到该控制器的路由时,它工作。

The thing is, it works when I set up with a route to that controller

推荐答案

控制器不会自己运行,它们作为Laravel的组件。如果你直接加载你的控制器,那么Laravel不会被加载,就PHP而言, BaseController ,以及Laravel的 Controller 类,不存在。通常,您的Web服务器加载加载Laravel等的 public / index.php 如果有困惑,您可能想了解如何使用Composer自动加载功能: http:// net.tutsplus.com/tutorials/php/easy-package-management-with-composer/

Controllers don't run by themselves, they work as a component of Laravel. If you're loading your controller directly then Laravel is not being loaded and as far as PHP is concerned BaseController, as well as Laravel's Controller class, does not exist. Normally your web server loads public/index.php which loads Laravel and so on. If that's confusing you may want to learn about how autoloading with Composer works: http://net.tutsplus.com/tutorials/php/easy-package-management-with-composer/

您应该做的是编写Artisan命令,它执行您所需要的并使用cron调用该命令。此问题详细介绍了如何完成此操作: Laravel中的Cron作业

What you should do is write an Artisan command that does what you need and call that command using cron. This question gives details on how to accomplish this: Cron Job in Laravel

这篇关于Cron Job在Laravel 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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