Posts filed under 'codeIgniter'
Using Session in CI
Using Session:
For using Session in CI must have to add this following line:
$this->load->library( ’session’ );
Important Note: If you have to use session for different pages, in that case u have to write this same line each and every time. So, better not to use this line, but play with the CONFIG folder.
- go to the location “http://localhost/PROJECT_FOLDER/system/application/config/“
- open the file “autoload.php”
- than rewrite the variable $autoload['libraries'] = array( ‘session‘);
After than should have to assign session value like array:
[array]
( ’session_id’ => random hash,
‘ip_address’ => ’string – user IP address’,
‘user_agent’ => ’string – user agent data’,
‘last_activity’ => timestamp )
Retrieving data from session:
$session_id = $this->session->userdata( ’session_id’ );
Adding Custom Session Data:
$this->session->set_userdata( $array );
Where $array is an associative array containing your new data. Here’s an example:
$sessionArry= array(
‘username’ => ‘Lizee’,
‘email’ => ‘lizee@mysite.com’,
‘logged_in’ => TRUE,
‘usertype’ => ’superAdmin’,
);
$this->session->set_userdata( $sessionArry );
userdata , set_userdata are the library function. So, never and every change those.
Add comment August 21, 2009
Starting Codeigniter
Codeigniter (CI ), name of PHP Framework. 1year ago I was willing to start working on it. I search on net, read some books. but, still i was confused, how to do what! And i did nothing. by this time, i got a professional work which have to develop with CI. So, i was bound to learn it.
Now, i am confident on CI. Those who are willing to start learning CI, but don’t know from where to start. I hope this post will be help those learners to start up.
At first you have to install and configure. for that please visit:
http://codeigniter.com/user_guide/installation/index.html
Before starting CI, its very important to know, how CI is designed. There we go:
Codeigniter is MCV patter framework.
- M-MODEL (All kind of query related code will be here)
- V-VIEW (All kiind of htlm code will be place here)
- C-CONTROLLER (This is the BOSS, who control the whole system)
Now, we will create a very simple page. Lets create a registration form, where any User will input their information. For that what we have to follow some steps:
- Create a View file which will display the Registration form.
- Create a Controller file, which will call the Registration page and collect the data
- Create Model,which will save all data on database.
to be continued…
Add comment August 12, 2009
CodeIgniter image upload
When I first time try to write code for image upload on Codeigniter, I had to face problems. I dig and dig and dig. I search on CI guide. but, thats not enough to help me. Well, finally I did it. If someone stuck on CI image upload, hope it will help them a lot.
There are some easy steps to upload image on CI :
- Create the form normally how it should create for upload a photo on php. Must add “enctype=”multipart/form-data”
- open controler file. under the upload image function write down following code :
- $config[ 'upload_path' ] = ‘./uploads/’ ; // destination folder path
- $config[ 'allowed_types' ] = ‘gif|jpg|png’ ; // Allowed uploaded file type
- $config[ 'max_size' ] = ‘2048′ ;// Allowed uploaded file’s max size
- $this->load->helper( array( ‘form’ , ‘url’ ) ) ;
- $this->load->library( ‘upload’ , $config);
- $image_up = $this->upload->do_upload(‘image‘);
- $image_data = array(‘upload_data’ => $this->upload->data());
- $image_up is where image upload information will be safe, it will return 1 if image uploaded successfully.
- $config is very important variable. for details of “$config” variable’s parameters you must have to see the manual
- $image_data will carry the uploaded image information.
- BLUE marked words are library function.
- image is form name
Add comment July 24, 2009