自己建立的類別函數可以存放在 application/libraries 資料夾
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Myclass {
public function js_alert($str1,$str2='')
{
echo "<meta http-equiv=Content-Type content=text/html; charset=utf-8>";
if($str2=='')
{echo "<script>alert('$str1');history.go(-1);</script>";exit();}
else
{echo "<script>alert('$str1');location.href='$str2';</script>";exit();}
exit();
}
}
/* End of file Myclass.php */
=====================================================================
控制器(Controller)
public function __construct()
{
parent::__construct();
$this->load->library('myclass'); //載入class
$this->load->helper('url');
$this->load->model('login_checkpower');
}
public function checkpower()
{
$ac = $this->input->post('ac');
$pwd = $this->input->post('password');
$data['admin'] = $this->login_checkpower->get_one($ac,md5($pwd));
if(count($data['admin'])==0){
$this->myclass->js_alert('請輸入正確帳號、密碼!'); //使用公用function
}
echo "登入成功!";
}
沒有留言:
張貼留言