我编写了自己的Code Igniter模型来发送电子邮件.一切都很好,直到最近我才开始出现这个错误:
致命错误:无法在第2319行的/home/mysite/public_html/subdir/application/libraries/phpmailer/class.phpmailer.php中重新声明类phpmailerException
我正在使用:
CodeIgniter 2 PHPMailer 5.1
我尝试过以下方法来解决它:
这是我的控制器方法(公司/联系人),它调用我的模型(message_model):
function contact()
{
//Do settings.
$this->options->task='email';
$this->options->change = 'sent';
$this->options->form_validation='';
$this->options->page_title='Contact Us';
//Import library
include_once('application/libraries/recaptcha/recaptchalib.php');//Include recaptcha library.
//Keys for recaptcha, stored in mainconfig file.
$this->options->publickey = $this->config->item('recaptcha_public');
$this->options->privatekey = $this->config->item('recaptcha_private');
//Form validation
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$this->form_validation->set_rules('name_field','Name of problem','trim|required|min_length[3]|max_length[100]');
$this->form_validation->set_rules('desc_field','Description','trim|required|min_length[10]|max_length[2000]');
$this->form_validation->set_rules('email_field','Your email address','trim|required|valid_email');
$this->form_validation->set_rules('recaptcha_response_field','captcha field','trim|required|callback__check_recaptcha');
//If valid.
if( $this->form_validation->run() )
{
//Set email contents. …Run Code Online (Sandbox Code Playgroud) 我正在使用Ion Auth作为我的codeigniter应用程序,除了一件事,一切似乎都很好.
我需要显示一个用户列表以及他们所在的组.如何在不创建自己的模型和查询的情况下检索特定用户的组ID.
$this->ion_auth->user($id)->row(); 不检索组ID.
我正在开发一个Web应用程序,我打算在不久的将来推出iPhone和Android版本,我有一些关于开发API以供不同前端使用的问题.
我正在阅读这个TutsPlus教程,该教程讨论创建以API为中心的Web应用程序,这意味着您的所有浏览器调用和智能手机应用程序调用都通过API进行路由.
特别让我兴奋的是Twitter的教程中的这句话:
最重要的架构变化之一是Twitter.com现在是我们自己的API的客户端.它从移动站点,我们的iPhone,iPad,Android应用程序和每个第三方应用程序使用的相同端点获取数据.
以上陈述反映了我理想的创作方式.
我找到了这个TutsPlus教程,它讲述了如何为CodeIgniter构建REST API.这很好,因为我正在使用Modular Extensions插件--HMVC在CodeIgniter中开发我的应用程序,我认为这对我的目的来说是完美的.
唯一的一点,那我有点失去了,就是这样,菲尔鲟鱼似乎暗示创建API.他建议完成所有前端代码模块,然后为各自目录中的每个模块创建一个API(不一定按此顺序).如果我不希望它以API为中心,那就没问题了.
我应该如何继续混合使用这两个教程:
我是不是该:
我从用于手机的回调函数没有验证这里.
function valid_phone_number_or_empty($value)
{
$value = trim($value);
if ($value == '') {
return TRUE;
}
else
{
if (preg_match('/^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/', $value))
{
return preg_replace('/^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/', '($1) $2-$3', $value);
}
else
{
return FALSE;
}
}
}
Run Code Online (Sandbox Code Playgroud)
但现在的问题是它不接受来自欧洲国家和世界其他地区的11至13位数的电话号码.任何人都可以为我提供任何其他所有国家的通用验证吗?
我正在使用REST_Controller扩展CI_Controller,由于某种原因,我的请求都返回了内容类型的text/html而不是json.在我的配置中,我将json设置为默认格式:
$config['rest_default_format'] = 'json';
Run Code Online (Sandbox Code Playgroud)
我的结果以JSON的形式返回,但内容类型未设置.任何人都可以帮助我缺少的东西吗?
我需要运行一个返回多行并将其导出为CSV的查询.我必须按照一定的顺序放置细胞.
所以,让我说我的桌子是id,姓名,地址,妻子.我需要按照id,address,wife,name的顺序构建一个csv.我想我可以按照正确的顺序制作一个数组,然后用它制作一个csv但是经过一个小时的谷歌搜索我无法找到如何用数组制作一个csv.
有fputcsv但需要预先制作的csv.此外,我希望有一个codeigniter方式来做到这一点.
public function export() {
$this->load->helper('download');
$data[1] = 'i like pie';
$data[2] = 'i like cake';
force_download('result.csv', $data);
}
Run Code Online (Sandbox Code Playgroud)
我试过了,但错误说下载帮助文件期望字符串不是数组.
我有以下项目结构
/system
/applications
/cache
/core
/helpers
/hook
/language
/libraries
/logs
/third_party
/admin-panel
/config
/controllers
welcome.php
dashboard.php
/errors
/models
/views
welcome.php
dashboard.php
/user-panel
/config
/controllers
welcome.php
dashboard.php
/errors
/models
/views
welcome.php
dashboard.php
/admin
index.php
index.php
Run Code Online (Sandbox Code Playgroud)
我的项目文件夹中的index.php将user-panel作为我的应用程序文件夹,admin文件夹中的index.php将admin-panel作为我的应用程序文件夹.
我插入了这行$ route ['default_controller'] ="welcome"; $ route ['welcome'] ='welcome'; 在users.php中,在user-panel和admin-panel中
我可以通过使用访问我的用户面板和管理面板的欢迎控制器 http://localhost/myproject and http://localhost/myproject/admin
但我无法通过使用访问我的仪表板控制器 http://localhost/myproject/dashboard or http://localhost/myproject/admin/dashboard
我的仪表板控制器可以使用 http://localhost/myproject/index.php/dashboard or http://localhost/myproject/admin/index.php/dashboard
但我不希望index.php包含在我的网址中.我想删除它.我也试过在我的管理文件夹中使用.htaccess.我在这里写下面的一行
RewriteEngine On
RewriteCond $1 !^(index\.php|(.*)\.swf|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Run Code Online (Sandbox Code Playgroud)
但这对我不起作用.它给出了404未找到的CI错误.我还通过在httpd.conf中将AllowOerride None更改为AllowOverride All来启用mod_rewrite.请告诉我如何删除index.php以及我应该将.htaccess文件放在项目目录中的哪个位置.
当您没有代理IP列表时会发生什么?使用Akamai,Google,Edgecast或CloudFront等网站加速服务时; 从他们那里获取会话的IP总是很难.
在CDN上测试我们的codeigniter应用程序时,我们注意到IP作为CDN IP而不是会话数据库中的客户端IP传递.
你怎么能绕过这个?
/*
|--------------------------------------------------------------------------
| Reverse Proxy IPs
|--------------------------------------------------------------------------
|
| If your server is behind a reverse proxy, you must whitelist the proxy IP
| addresses from which CodeIgniter should trust the HTTP_X_FORWARDED_FOR
| header in order to properly identify the visitor's IP address.
| Comma-delimited, e.g. '10.0.1.200,10.0.1.201'
|
*/
$config['proxy_ips'] = '';
Run Code Online (Sandbox Code Playgroud)
谢谢!
我的Codeigniter 2.1.0应用程序中有这个错误控制器:
<?php
class Error extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
set_status_header(404);
$data->menuItems = Main::_menu();
$data->title = "404 error !";
$data->pageview = 'templates/404';
$this->load->view('templates/main', $data);
}
public function facebook()
{
set_status_header(404);
$data->menuItems = Main::_menu();
$data->title = "Facebook error !";
$data->pageview = "templates/facebook_error";
$this->load->view('templates/main', $data);
}
}
?>
Run Code Online (Sandbox Code Playgroud)
主控制器_menu:
<?php
class Main extends CI_Controller
{
// ... a lot of methods here ...
public static function _menu()
{
static $menuItems = array( //just a …Run Code Online (Sandbox Code Playgroud) 在使用转换后的查询中转义整数是否有任何意义intval()?
我正在使用这样的整数:
$sql .= " LIMIT " . $this->db->escape(intval($offset)) . ", 10";
Run Code Online (Sandbox Code Playgroud) codeigniter ×10
php ×9
rest ×2
arrays ×1
content-type ×1
controller ×1
csv ×1
database ×1
download ×1
ion-auth ×1
json ×1
mysql ×1
phone-number ×1
phpmailer ×1
proxy ×1
session ×1
validation ×1