Saturday, October 24, 2009

Codeigniter Send Email using Gmail

<?

class Emailer extends Controller

{

function Emailer()

{

parent::Controller();

}

function index()

{

$config = Array(

'protocol' => 'smtp',

'smtp_host' => 'ssl://smtp.googlemail.com',

'smtp_port' => 465,

'smtp_user' => 'yourusername@gmail.com',

'smtp_pass' => 'yourpassword',

'mailtype' => 'html',

'charset' => 'iso-8859-1',

'wordwrap' => TRUE

);


$this->load->library('email', $config);

$this->email->set_newline("\r\n");


$this->email->from('dixanta@creatorsnepal.com');

$this->email->to('dixanta@hotmail.com');

$this->email->subject('This is an email test');

$this->email->message('It is working. Great!');


if($this->email->send())

{

echo 'Your email was sent, fool.';

}


else

{

show_error($this->email->print_debugger());

}

}

}

Friday, October 23, 2009

Easy way to switch language

Create a library named MY_Controller.php and place in your system/application/libraries

and paste the code below


class Front_Controller extends Controller

{


var $current_culture='';


function Front_Controller()

{

parent::Controller();

if($this->session->userdata('language'))

{

$this->config->set_item('language',$this->session->userdata('language'));

$this->config->set_item('language_code',$this->session->userdata('language_code'));

}

$this->current_culture=$this->config->item('language');

$this->culture_code=$this->config->item('language_code');

}


function set_current_culture($language)

{

$this->session->set_userdata('language',strtolower($language));

}


}

}


Create your controller and extend it with Front_Controller class


For example:

class Home extends Front_Controller

{

function Home()

{

parent::Front_Controller();


}


function index()

{

$data['title']='Switch Language Example';

$this->load->view('home',$data);

}


// Function if you are doing post from FORM

function language()

{

$this->set_language($this->input->post('currlang'));

}


//Function if you are selecting from the Link


function set_language($language_code)

{

$this->set_current_culture($language_code);

redirect(site_url('home'));

}


}


create your view.


You are done.


Easy way to switch language

Create a library named MY_Controller.php and place in your system/application/libraries

and paste the code below


class Front_Controller extends Controller

{


var $current_culture='';


function Front_Controller()

{

parent::Controller();

if($this->session->userdata('language'))

{

$this->config->set_item('language',$this->session->userdata('language'));

$this->config->set_item('language_code',$this->session->userdata('language_code'));

}

$this->current_culture=$this->config->item('language');

$this->culture_code=$this->config->item('language_code');

}


function set_current_culture($language)

{

$this->session->set_userdata('language',strtolower($language));

}


}

}


Create your controller and extend it with Front_Controller class


For example:

class Home extends Front_Controller

{

function Home()

{

parent::Front_Controller();


}


function index()

{

$data['title']='Switch Language Example';

$this->load->view('home',$data);

}


// Function if you are doing post from FORM

function language()

{

$this->set_language($this->input->post('currlang'));

}


//Function if you are selecting from the Link


function set_language($language_code)

{

$this->set_current_culture($language_code);

redirect(site_url('home'));

}


}


create your view.


You are done.


Sunday, October 18, 2009

Convert XML to object in Codeigniter

Here is the library to convert XML to object in Codeigniter

class CI_Xml_Handle
{
var $xml='';

function CI_Xml_Handle($xml_content)
{
$this->xml=$xml_content;
}

function XMLtoObject () {
try {
$xml_object = new SimpleXMLElement($this->xml);
if ($xml_object == false) {
return false;
}
}
catch (Exception $e) {
return false;
}

return $xml_object;
}


}

loading model in another model in CodeIgniter

Here I will show you how easy it is to load model inside another model in Codeigniter.

Say we have 2 models which are as follows:

class First_model extends Model
{
function First_model()
{
parent::Model();
}

function First_Function()
{
echo 'This is parent Function';
}
}

class Second_model extends Model
{
function Second_model()
{
parent::Model();

//Load First Model
$ci=& get_instance();
$ci->load->model('First_model');
}

function Second_Function()
{
//Call First model Function
$ci->First_model->First_Function();

}
}

You are Done.

Friday, October 16, 2009

Understand Model-View-Controller in Codeigniter

CodeIgniter is based on the Model-View-Controller development pattern. MVC is a software approach that separates application logic from presentation. In practice, it permits your web pages to contain minimal scripting since the presentation is separate from the PHP scripting.



  • The Model represents your data structures. Typically your model classes will contain functions that help you retrieve, insert, and update information in your database.
  • The View is the information that is being presented to a user. A View will normally be a web page, but in CodeIgniter, a view can also be a page fragment like a header or footer. It can also be an RSS page, or any other type of "page".
  • The Controller serves as an intermediary between the Model, the View, and any other resources needed to process the HTTP request and generate a web page.

CodeIgniter has a fairly loose approach to MVC since Models are not required. If you don't need the added separation, or find that maintaining models requires more complexity than you want, you can ignore them and build your application minimally using Controllers and Views. CodeIgniter also enables you to incorporate your own existing scripts, or even develop core libraries for the system, enabling you to work in a way that makes the most sense to you.

Facebook Connect CodeIgniter Library

This library is essentially a wrapper for the Facebook PHP API, but also includes everything you need to get Facebook Connect working with in your CodeIgniter libraries.

This is an early (beta)-ish release, so the documentation isn’t too great, just wanted to get this out in the wild.

Overview
=========================
This package includes everything you need to get your application using both the server-side facebook api and client-side facebook connect functions.

You can read more about this at http://www.haughin.com/code/facebook/

Licensing
=========================
facebook-client directory and contents licensed by Facebook.
All other contents licensed under GNU/GPL (see license.txt)

Basic setup instructions
=========================
1. Copy the files within application/ to your CodeIgniter application directory.
Included is one config file (facebook.php), one library file (facebook_connect.php), the facebook-client
one sample controller (home.php), and one sample view file (fbtest.php).

2. Copy xd_receiver.htm to the root of your CodeIgniter install (in the same directory as CI’s index.php)

3. Go to facebook developer application and register your application ( http://www.facebook.com/developers/ )

4. Copy your API and Secret key to config/facebook.php

5. In the facebook developer application, set your ‘Connect URL’ under the connect tab, to the CodeIgniter application url.

I.E. http://mygroovyapp.com/

6. If your application lives on a subdomain (like : http://my.groovyapp.com ) set your ‘base domain’ under the connect tab to the top level domain of your application ( in this case: groovyapp.com )

7. Give it a go!
Download Facebook Connect CodeIgnter Library

License: GNU GENERAL PUBLIC LICENSE – Version 2
Version: 1.0

source: http://www.haughin.com/code/facebook/