顯示具有 CodeIgniter 標籤的文章。 顯示所有文章
顯示具有 CodeIgniter 標籤的文章。 顯示所有文章

2015年3月23日 星期一

CodeIgniter composite primary key

$this->dbforge->add_key('blog_id', TRUE);
$this->dbforge->add_key('site_id', TRUE);
// gives PRIMARY KEY `blog_id_site_id` (`blog_id`, `site_id`)




References :
model - Codeigniter MY_Model composite primary key - Stack Overflow

CodeIgniter Insert on duplicate

$orig_db_debug = $this->db->db_debug;

$this->db->db_debug = FALSE;

RUN QUERY HERE

$this->db->db_debug = $orig_db_debug;




References :
Dealing with duplicate keys in codeigniter mysql insert - Stack Overflow

2015年1月13日 星期二

CodeIgniter form validation functions

codeigniter/libraries/Form_validation.php

    public function required($str)
    public function regex_match($str, $regex)
    public function matches($str, $field)
    public function is_unique($str, $field)
    public function min_length($str, $val)
    public function max_length($str, $val)
    public function exact_length($str, $val)
    public function valid_email($str)
    public function valid_emails($str)
    public function valid_ip($ip, $which = '')
    public function alpha($str)
    public function alpha_numeric($str)
    public function alpha_dash($str)
    public function numeric($str)
    public function is_numeric($str)
    public function integer($str)
    public function decimal($str)
    public function greater_than($str, $min)
    public function less_than($str, $max)
    public function is_natural($str)
    public function is_natural_no_zero($str)
    public function valid_base64($str)
    public function prep_for_form($data = '')
    public function prep_url($str = '')
    public function strip_image_tags($str)
    public function xss_clean($str)
    public function encode_php_tags($str)

2015年1月10日 星期六

CodeIgniter Disallowed Key Characters error

fix your regex rule
$ vi system/core/input.php
if ( ! preg_match("/^[a-z0-9:_\/-|]+$/i", $str))
{
    exit('Disallowed Key Characters.');
}







References :
Disallowed Key Characters error / Forums / Community / EllisLab


2014年12月23日 星期二

PHP echo json_encode error

Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at )


origin :
...
echo json_encode($myarray);

fix :
...
header("Content-type: application/json; charset=utf-8");
echo json_encode($myarray);
die;









References :
Output.php with compress_output = true, always calls ob_start(‘ob_gzhandler’) causing warning with ajax / Forums / Community / EllisLab

2014年12月16日 星期二

Bonfire flash message

在 Controller 裏 Template::render 前使用 set_message:
Template::set_message('Your message displayed just fine.', 'success');

在 View 裏,欲顯示通知訊息的地方加入:
echo Template::message();


另一種手動的方法爲:

Controller :
$message['type'] = 'success';
$message['message'] = 'Your message displayed just fine.';
Template::set('message', $message);
View :
 <div class="alert alert-block alert-{type} fade in notification">
    <a data-dismiss="alert" class="close" href="#">×</a>
    <div>{message}</div>
</div>



 
References :
Docs - My Bonfire
Template::message problem - Bonfire Forums

2014年11月24日 星期一

CodeIgniter api route

http://localhost:81/index.php/api/user/index/1
http://localhost:81/index.php/api/user/1
http://localhost:81/index.php/api/user

Route::any('api/(:any)/(:any)/(:num)', '$1/api/$2/$3');
Route::any('api/(:any)/(:num)', '$1/api/index/$2');
Route::any('api/(:any)/(:any)', '$1/api/$2');
Route::any('api/(:any)', '$1/api');

public function index($id = FALSE)
{  
    $return_data = array('user_id' => $id, 'status' => 'success', message' => '');
                                                                                                                                   
    echo json_encode($return_data);
}




References :
Parsing URI segments and assigning them to variables - Bonfire Forums
Docs - My Bonfire

2014年11月16日 星期日

CodeIgniter get insert id

$this->xxx_model->insert($data);
$this->db->insert_id();




References :
php - CodeIgniter activerecord, retrieve last insert id? - Stack Overflow

CodeIgniter SESSION

$this->load->library("session");  // if you not load
 
$this->session->set_userdata("SESSION_NAME","VALUE");
echo $this->session->userdata("SESSION_NAME");  




References :
php - How to save and extract session data in codeigniter - Stack Overflow

2014年11月10日 星期一

Bonfire database migration

  1. Enter Web, Database / Database Tools / Migrations
    http://localhost/index.php/admin/developer/migrations
  2.  auto migrates
$ vi application/config/config.php
$config['migrate.auto_core']  = TRUE;
$config['migrate.auto_app']   = FALSE;




References :
Docs - My Bonfire