Codeigniter: Store value of a dropdown into session variable


I have a dropdown in the login page which fetches company codes and
it's respective ID as value. I need to store this particular value
(ID) in a session variable so I may use it throughout site. So that
when that particular company is selected I may be able to view the
details of that particular company. If there is an alternate method
for this, kindly let me know.



MODEL:



public function login ()
{
$user = $this->get_by(array(
'company_id' => $this->input->post('company_id'),
'username' => $this->input->post('username'),
'password' =>
$this->hash($this->input->post('password')),
), TRUE);

$this->session->set_userdata($user);
if (count($user)) {
// Log in user
$data = array(
'username' => $user->username,
'id' => $user->id,
'loggedin' => TRUE,
'is_admin' => $user->is_admin,
'company_id' => $user->company_id
);
$this->session->set_userdata($data);
return TRUE;
}

}


VIEW:



<tr>
<td>Location</td>
<td><select class="form-control" id="company_code"
name="company_code" required>
<option value="0" selected>Select
Company</option>
<?php foreach($locations as $location){
$selected =
$user->company_id==$location->company_id?"selected='selected'":'';
echo "<option $selected
value='".$location->company_id."'>".$location->company_code."</option>";
}?>
</select>
</td>
</tr>
<tr>
<td>Username</td>
<td><?php echo
form_input('username','','class="form-control" placeholder="Enter User
Name"'); ?></td>
</tr>
<tr>
<td>Password</td>
<td><?php echo
form_password('password','','class="form-control" placeholder="Enter
Password"'); ?></td>
</tr>
<tr>
<td></td>
<td><?php echo form_submit('submit', 'Log in',
'class="btn btn-primary"'); ?></td>
</tr>


I want the above company_id to be posted into a
session variable so it maybe used throughout the program. Any help
will be greatly appreciated.


- Technology - Languages
+ Webmasters
+ Development
+ Development Tools
+ Internet
+ Mobile Programming
+ Linux
+ Unix
+ Apple
+ Ubuntu
+ Mobile & Tablets
+ Databases
+ Android
+ Network & Servers
+ Operating Systems
+ Coding
+ Design Software
+ Web Development
+ Game Development
+ Access
+ Excel
+ Web Design
+ Web Hosting
+ Web Site Reviews
+ Domain Name
+ Information Security
+ Software
+ Computers
+ Electronics
+ Hardware
+ Windows
+ PHP
+ ASP/ASP.Net
+ C/C++/C#
+ VB/VB.Net
+ JAVA
+ Javascript
+ Programming
Privacy Policy - Copyrights Notice - Feedback - Report Violation 2018 © BigHow