|
本帖最后由 大道达人 于 2012-2-20 13:23 编辑
为CIer们,分享几个简单的思路,菜蔬学浅,大家见谅
1.未登录情况下 URL的自动跳转返回a.创建MY_Controller,
PHP复制代码 class MY_Controller extends CI_Controller
{
public function __construct ()
{
parent ::__construct ();
//check user login status
//登陆跳转
if ( ! $this->session->userdata('uid'))
{
$redirect = $this->uri->uri_string();
if ( $_SERVER['QUERY_STRING'])
{
$redirect .= '?' . $_SERVER['QUERY_STRING'];
}
redirect ('user/login?redirect='.$redirect);
}
}
}
class User extends CI_Controller
{
public function login ()
{
//redirect host info
if ($this->session->userdata('uid'))
redirect ('/');
if ($_POST)
{
// use ldap for authentication
$ds = ldap_connect($this->config->item('ldap_host'));
if (!$ds)
{
die('failed to connect to LDAP server');
}
$valid = FALSE;
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION , $this->config->item('ldap_version'));
$valid = @ldap_bind($ds, "uid={$_POST['username']},{$this->config->item('ldap_base')}", $_POST['password']);
if ($valid )
{
//当前用户名不存在的情况下,insert记录
$obj_user = $this->host_model->checkUser($_POST['username']);
// create new user for valid ldap authentication
if (empty($obj_user))
{
$this->host_model->username = $_POST['username'];
if ($this->host_model->saveUser())
$this->session->set_userdata('uid',$this->db->insert_id());
}
else
$this->session->set_userdata('uid',$obj_user['id']);
}
else
{
die('invalid username or password');
}
$redirect = isset($_GET['redirect']) ? $_GET['redirect'] : '/';
redirect ($redirect);
}
$this->load->view('user_login');
}
}
class host extends MY_Controller
{
public function __construct ()
{
parent ::__construt ();
}
}
?>
复制代码
2.CI适配器的实际应用
电商系统需要对针对不同的支付方式进行处理,可以抽象成支配器的结构,如下:
--Payment
----dirvers
------Payment_cash.php
------Payment_pp.php
PHP复制代码
$this->load->driver('payment');
$this->payment->pp->pay(OrderStruct $order);
复制代码
3.基于API的脚本范例本范例来自phpclasses,仅提供大家设计API接口的思路
http://www.phpclasses.org/package/3219-PHP-Manipulate-domain-registration-using-the-Enom-API.html
payment.rar
(1.72 KB, 下载次数: 24)
|
评分
-
查看全部评分
|