Load a new view with the next record in the db - El Forum - 02-22-2011
[eluser]afro[/eluser]
Am developing a online leave management system and am stuck at this point of load a new view with the next leave for approval after an application has been approved or rejected by approving officer, what I want is that a new similar view should load when the submit button is clicked.
Please help me out.
Thank you.
Load a new view with the next record in the db - El Forum - 02-22-2011
[eluser]InsiteFX[/eluser]
Just load the new view like you normally do.
InsiteFX
Load a new view with the next record in the db - El Forum - 02-22-2011
[eluser]afro[/eluser]
@InsiteFX
The new view has to contain the details of the next pending leave so that it can be approved,i have a problem loading the data from the db to the new view
Load a new view with the next record in the db - El Forum - 02-22-2011
[eluser]InsiteFX[/eluser]
Show your method code where your getting the data from the database.
InsiteFX
Load a new view with the next record in the db - El Forum - 02-23-2011
[eluser]afro[/eluser]
1.the viewCode: <div id="leaveapproval"><?php echo $num_results;?> pending leave(s)found</b>
<?php echo form_open('administration/processleave');?><table border="1" align="center" id="leaveapprovaltable"><tbody><?php foreach($leaves as $leave):?><tr><td>Application Id</td><td><input type="text" name="applicationid" value="<?php echo $leave->ApplicationId;?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Staff Name</td><td><input type="text" name="staffname" value="<?php echo $leave->StaffName; ?>" readonly="readonly" onfocus="this.blur();"/></td></tr>
<tr><td>Leave Balance</td><td><input type="text" name="leavebalance" value="<?php echo $leave->LeaveBalance; ?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Days Requested</td><td><input type="text" name="noofdaysrequested" value="<?php echo $leave->NoofDaysRequested; ?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Leave Type</td><td><input type="text" name="leavetype" value="<?php echo $leave->LeaveType; ?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Commencement Date</td><td><input type="text" name="commencementdate" value="<?php echo $leave->CommencementDate; ?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Reporting Back</td><td><input type="text" name="Dateforreportingback" value="<?php echo $leave->Dateforreportingback;?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Current Project</td><td><input type="text" name="currentproject" value="<?php echo $leave->CurrentProject; ?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Handed To</td><td><input type="text" name="handedto" value="<?php echo $leave->HandedTo; ?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td>Comment</td><td><input type="text" name="comment" value="<?php echo $leave->Comment;?>" readonly="readonly" onfocus="this.blur();"/></td></tr><tr><td colspan="2" align="center"> Appove:<?php echo form_radio('approve','Approved');?>Reject: <?php echo form_radio('approve','Rejected');?></td></tr><tr><td colspan="2" align="center"><?php echo form_submit('leaveapproval','Submit Form'), form_reset('reset','Cancel');?></td></tr><?php endforeach; ?></tbody></table>
2.The controllerCode: class Administration extends Controller{
function processleave(){
parent::controller();$this->load->helper(array ('url')); $this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div id="prompt_error">', '</div>'); $this->form_validation->set_rules('approve','Approval','required');
if($this->form_validation->run()==FALSE)
{$this->load->view('administration'); else{$this->load->model('Administration_model');
$query = $this->Administration_model->approvedleaves();}
if($query){$offset=0,$limit = 1; $this->load->model('Administration_model');
$results = $this->Administration_model->search($limit, $offset);$data['leaves'] = $results['rows'];
$data['num_results'] = $results['num_rows'];$this->load->library('pagination');
$config = array();$config['base_url'] = site_url("Administration_model/search");
$config['total_rows'] = $data['num_results'];$config['per_page'] = $limit; $config['uri_segment'] = 5; $this->pagination->initialize($config); $data['pagination'] = $this->pagination->create_links();
redirect('administration',$data);}}
public function nextleave()
{$offset=0,$limit = 1;$results = $this->search($limit, $offset);$data['leaves'] = $results['rows'];
$data['num_results'] = $results['num_rows'];$this->load->library('pagination'); $config = array(); $config['base_url'] = site_url("Administration_model/search"); $config['total_rows'] = $data['num_results']; $config['per_page'] = $limit; $config['uri_segment'] = 5;$this->pagination->initialize($config); $data['pagination'] = $this->pagination->create_links(); redirect('administration',$data);}}
3. The model class is as follows
Code: class Administration_model extends Model{
public function search($limit, $offset)
{parent::Model();
$q = $this->db->select('ApplicationId, StaffName, LeaveBalance, NoofDaysRequested, LeaveType, CommencementDate, Dateforreportingback, CurrentProject, HandedTo, Comment');
$this->db->from('appliedleaves');
$where = "Status = 'Pending'";
$this->db->where($where);$this->db->limit($limit, $offset);$ret['rows'] = $q->get()->result();
$q= $this->db->select('COUNT(*) as count', FALSE); $where = "Status = 'Pending'"; $this->db->where($where);
$this->db->from('appliedleaves'); $tmp = $q->get()->result(); $ret['num_rows'] = $tmp[0]->count;return $ret;}
function approvedleaves(){
$approve = "Status ='" . mysql_real_escape_string($this->input->post('approve')) . "' WHERE ApplicationId LIKE " . mysql_real_escape_string($this->input->post('applicationid'));
$query = $this->db->update('appliedleaves',$approve);
if($query = 1)
{$approvedleaves=array('ApplicationId'=>$this->input->post('applicationid'),'StaffName'=>$this->input->post('staffname'),'LeaveBalance'=>$this->input->post('leavebalance'),'DaysRequested'=>$this->input->post('noofdaysrequested'),'LeaveType'=>$this->input->post('leavetype'),'CommencementDate'=>$this->input->post('commencedate'),'ReportingBack'=>$this->input->post('dateforreportingdate'),'CurrentProject'=>$this->input->post('currentproject'),'HandedTo'=>$this->input->post('handedto'),'Comment'=>$this->input->post('comment') );
$query = $this->db->insert('helpdesklevel_leaves', $approvedleaves);
if($query){
/*i want after the approved/rejected leave has been saved, i want the system to load the next leave from the db to the view at this point*/
class Administration::nextleave();}}}}
Load a new view with the next record in the db - El Forum - 02-23-2011
[eluser]InsiteFX[/eluser]
If your using CodeIgniter 2.0.0 then you need to change Controller to CI_Controller and Model to CI_Model.
And I hope you do not expect us to try and read that code!
Look in the CodeIgniter User Guide database active record!
InsiteFX
Load a new view with the next record in the db - El Forum - 02-24-2011
[eluser]afro[/eluser]
I got a way that solved that particular problem
Thanks anyway for trying to help
I came up with a helper class that i called at the end of the
controller class and to my surprise it worked, am know almost thru' with
the system.
|