1
我正在yii2中運行應用程序。我創建了一個命令控制器/命令/的TestControlleryii2 cron給出「找不到PDO」的錯誤
<?php
namespace app\commands;
use app\models\UserProfile;
use yii\console\Controller;
use app\controllers\AppController;
/**
* Test controller
*/
class TestController extends Controller
{
public function actionIndex()
{
echo "cron service running";
}
public function actionSendBirthdaySms()
{
$userProfile = UserProfile::find()
->where('MONTH(dob) = MONTH(DATE(NOW()))')
->andWhere('DAY(dob) = DAY(NOW()) ')
->with('user')
->asArray()
->all();
foreach($userProfile as $item){
$birthdayMessage = "Happy Birthday " . $item['user']['username'];
//to send sms
$this->_send_cron_sms($item['mobile'], $birthdayMessage);
}
}
我有兩個功能在這裏。當我打電話給php /home/user/public_html/yii test/index
時,它會給命令行和cron兩者提供正確的輸出。
但是當我運行php /home/user/public_html/yii test/send-birthday-sms
時,它在ssh環境下運行命令行並且我正在接收SMS。但在cron中給錯誤。這裏是我收到的電子郵件:
Status: 500 Internal Server Error
X-Powered-By: PHP/5.4.39
Content-type: text/html
PHP Fatal Error 'yii\base\ErrorException' with message 'Class 'PDO' not found'
in /home/user/public_html/vendor/yiisoft/yii2/db/Connection.php:609
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}
我也試過查詢生成器,但它也沒有幫助我。