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

2015年5月28日 星期四

CI Bonfire read global config variable

Example:

Config file :
application/config/address.php

Controller :
$this->load->config('address');
$address = config_item('address.countries');

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)

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月10日 星期一