Saturday, December 4, 2010

Codeigniter 2.0 Controller

class Welcome extends CI_Controller
{
function __construct()
{
parent::__construct();
}
}

Friday, August 6, 2010

Bit.ly Codeigniter

as simple as
$this->load->library('bitly');

then echo.simple!
echo $this->bitly->shorten('http://aizuddinmanap.blogspot.com/'); 

http://github.com/patrickpopowicz/bit.ly-Library-for-CodeIgniter/

Sunday, July 25, 2010

Form Validation Callbacks in HMVC in Codeigniter problem

create a file name MY_Form_validation.php and put it in the application/libraries folder
< ?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Form_validation extends CI_Form_validation
{
 function run($module = '', $group = '') {
 (is_object($module)) AND $this->CI =& $module;
 return parent::run($group);
 }
}
/* End of file MY_Form_validation.php */
/* Location: ./application/libraries/MY_Form_validation.php */  

when using validation, put $this into the $this->form_validation->run()
example
if($this->form_validation->run($this)) {
//your code down there 
}

Thursday, July 1, 2010

Saturday, June 19, 2010

Codeigniter Route Everything, except these Controllers

another Codeigniter routes, Codeigniter Route Everything, except these Controllers

There was a recent post on the codeigniter forums trying to get urls like these:
http://yoursite.com/your-slug
This problem could have been easily resolved using this route:
$route['(:any)'] = 'articles/$1';

In this route, all characters after the domain will be passed to the controller, 'article'.

However, the problem was he also had some controllers that he didn't want to use the route for. A quick fix for the route was to use a 'simple' regex using negative lookahead
$route['^(?!controller|controller|controller)\S*'] = "article/$1";


p/s:original post from here

codeigniter routes

how to use http://localhost/receipt/view/1 as http://localhost/receipt/1 ?
routes is the solution.

1)edit /application/config/routes.php

2)
$route['receipt/(:num)'] = "receipt/view/$1";

Wednesday, June 16, 2010

Form generator for CodeIgniter

Nice tool to generate form. http://formigniter.org

Problems $_GET if using .htaccess to remove index.php

1) Use this .htaccess to fix and remove index.php

    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
 

2)edit your application/config.php
$config['uri_protocol'] = "AUTO";
to
$config['uri_protocol'] = "PATH_INFO";
3) Put to your controller
parse_str($_SERVER['QUERY_STRING'],$_GET);

3)start using $_GET or
$this->input->get('input');

p/s: original post are here

Friday, June 11, 2010

codeigniter callback function to check valid username or email

this post are from here http://scottblaine.com/form-validation-callbacks-and-private-functions

If you’re familiar with CodeIgniter you probably know about callbacks within form validation. Callbacks allow you to do your own validation of fields. For example, if you want to verify if a username is unique then you could create a username_check function to validate the field. You add the callback rule like this:
1
2
$this->form_validation->set_rules( 'username', 'Username',
  'trim|required|callback_username_check' );
And then create a matching function like this:
1
2
3
4
5
function username_check( $username )
{
  // some code
}
?>
However, as this is currently implemented someone could access your function as a page at a URL like example.com/index.php/login/username_check/ if they guessed the function name. While that may not have any ill side-effects, it’s probably just as well if no one can access the function besides you.
In come private functions for controllers, which allow you to create a function like this:
1
2
3
4
function _utility()
{
  // some code
}
And if you try to access the function via a URL, like example.com/index.php/login/_utility/, you’ll get a 404 (page not found).
You probably see where I’m going with this. If you create your callbacks as private functions, no one will be able to access the callbacks as pages. It’s quite simple to do. You add an underscore before your callback function name:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function _username_check( $username )
{
  $valid_username = TRUE; // You would perform some kind of check on the field here
 
  if ($valid_username == FALSE)
  {
    $this->form_validation->set_message('_username_check', 'The username you have provided is not valid.');
    return FALSE;
  }
  else
  {
    return TRUE;
  }
}
And then add an underscore in your callback rule (note the two underscores after callback):
1
2
$this->form_validation->set_rules( 'username', 'Username',
  'trim|required|callback__username_check' );
Done!