我需要运行CI控制器>来自外部php脚本的方法..外部php脚本使用curl
$url = 'http://domain.com/ci_system/billing/success';
$fields = array(
'ammount' => $extra[0]['ammount'],
'email' => $extra[0]['email'],
'cemail' => $extra[0]['cemail'],
'rcode' => $completeResponse->getResponseCode(),
'message' => $completeResponse->getResponseText()
);
$post = http_build_query($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_exec($ch);
curl_close($ch);
以上成功功能我必须发送电子邮件。 curl
将所有必需的数据发送到成功函数但不起作用。当我手动触发此功能时,它可以工作..
$this->cart->destroy();
$ord = array(
'online' => 1
);
$this->Billing_model->updateOrder($ord, $this->session->userdata('data_o_i'));
//send email to the client
$this->load->library('email');
$config['protocol'] = 'sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from('noreply@zxzxzxz.com', 'Dsd Retail New Order');
$this->email->to($this->input->post('omail@gmail.com'));
$this->email->subject('You have a new message for yor order');
$this->email->message($this->input->post('email'));
答案 0 :(得分:2)
首先检查您的操作是否正常工作,如果从网址调用,则会给您预期的行为。
我有以下ci3设置。
<强>主机强>
$ sudo tar -vxjf sublime_text_3_build_3065_x32.tar.bz2 -C /opt
Apache网站可用
$ cat /etc/hosts
127.0.0.1 ci3.local
CI3 / htaccess的
cat /etc/apache2/sites-available/ci3.conf
<VirtualHost *:80>
ServerAdmin email@email.com
ServerName ci3.local
DocumentRoot /home/user/project/ci3
ErrorLog ${APACHE_LOG_DIR}/ci3_error.log
CustomLog ${APACHE_LOG_DIR}/ci3_access.log combined
SetEnv APPLICATION_ENV "development"
<Directory /home/user/project/ci3>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Allow from all
</Directory>
</VirtualHost>
CI3 /应用/配置/ routes.php文件
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
CI3 /应用/控制器/ Billing.php
$route['billing/success'] = 'billing/success';
现在,如果我从浏览器请求http://ci3.local/billing/success,它会将以下输出记录到我的日志文件
<?php
class Billing extends CI_Controller {
public function success()
{
log_message('debug', 'Billing.success');
log_message('debug', $this->input->post('amount'));
}
}
如何从终端拨打电话并检查它是否正常工作?
DEBUG - 2015-12-07 08:47:34 --> UTF-8 Support Enabled
DEBUG - 2015-12-07 08:47:34 --> Global POST, GET and COOKIE data sanitized
DEBUG - 2015-12-07 08:47:34 --> Billing.success
DEBUG - 2015-12-07 08:47:34 -->
DEBUG - 2015-12-07 08:47:34 --> Total execution time: 0.0019
然后我应该看到我的日志条目如下
$ curl --data "amount=200" http://ci3.local/billing/success
如何通过http?
从CURL调用此操作CI3 / curl.php
DEBUG - 2015-12-07 08:49:38 --> UTF-8 Support Enabled
DEBUG - 2015-12-07 08:49:38 --> Global POST, GET and COOKIE data sanitized
DEBUG - 2015-12-07 08:49:38 --> Billing.success
DEBUG - 2015-12-07 08:49:38 --> 200
DEBUG - 2015-12-07 08:49:38 --> Total execution time: 0.0021
从终端
调用curl.php<?php
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL => "http://ci3.local/billing/success",
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => array(
'amount' => '300'
)
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
然后我应该看到我的日志条目如下
php5 curl.php