• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
An uncaught Exception was encountered

#1
Any one can help me to handle below error.

An uncaught Exception was encountered
Type: ArgumentCountError
Message: Too few arguments to function Employee::view_profile(), 0 passed in C:\wamp64\www\MY\admin\system\core\CodeIgniter.php on line 532 and exactly 1 expected
Filename: C:\wamp64\www\MY\admin\application\controllers\Employee.php
Line Number: 128
Backtrace:
File: C:\wamp64\www\MY\admin\index.php
Line: 315
Function: require_once


Here this is my function...
public function view_profile($id)
{
   if ($this->session->userdata('NAME')) {
       $role = $this->session->userdata('ROLE');
       if ($role >= 1) {

           $employee_data["row"] = $this->Employee_model->view_data($id);
           //var_dump($employee_data); die();
           if ($employee_data["row"] == null) {
               $this->load->view('includes/header');
               $this->load->view('includes/top_header');
               $this->load->view('includes/left_nav');
               $this->load->view('error_page/404');
               $this->load->view('includes/footer');
               $this->load->view('includes/settings');
           } else {
               $this->load->view('includes/header');
               $this->load->view('includes/top_header');
               $this->load->view('includes/left_nav');
               $this->load->view('employee/view_employee_profile', $employee_data);
               $this->load->view('includes/footer');
               $this->load->view('includes/settings');
           }
       }
   }

}
Reply

#2
Like the error says, you aren't passing an $id to Employee::view_profile().
If you want to remove that error message and let the function die, you can change it into the following and pass a default value.

PHP Code:
public function view_profile($id 0)
{
 
  if ( !$id )
 
  {
 
      exit;
 
  }
 
  // your code here

Reply

#3
@sanjaya,
We need more information...like. The controller where the call was made (show all code).
Reply

#4
Model
<?php

Class Inventary_model extends CI_Model
{
public function __construct()
{
parent:: __construct();
}


public function get_company()
{
$query = $this->db->query("SELECT id, company_name FROM company WHERE id>=1");
$result = $query->result();
return $result;
}

public function get_employee()
{
$query = $this->db->query("SELECT * FROM employee WHERE id>=1");
$employee = $query->result();
return $employee;
}

public function add()
{
$data['item_name'] = $this->input->post('item_name');
$data['invoice_number'] = $this->input->post('invoice_number');
$data['company_id'] = $this->input->post('company_id');
$data['employee_id'] = $this->input->post('employee_id');
$data['description'] = $this->input->post('description');
$data['perchase_date']= $this->input->post('perchase_date');
$data['warranty_period'] = $this->input->post('warranty_period');
$data['warranty_end_date'] = $this->input->post('warranty_end_date');
$data['price'] = $this->input->post('price');
$data['qty'] = $this->input->post('qty');
$this->db->insert('inventory',$data);

}

public function list_item_data()
{
$query = $this->db->query("SELECT sgh.inventory.id,
sgh.inventory.item_name,
sgh.inventory.invoice_number,
sgh.inventory.description,
sgh.inventory.perchase_date,
sgh.inventory.warranty_period,
sgh.inventory.warranty_end_date,
sgh.inventory.price,
sgh.inventory.qty,
sgh.company.company_name,
sgh.inventory.company_id,
sgh.inventory.employee_id,
sgh.employee.employee_name
FROM
inventory
LEFT JOIN company ON inventory.company_id=company.id
LEFT JOIN employee ON inventory.employee_id=employee.id;
");

$row = $query->result_array();
return $row;

}

public function get_item($id)
{
$query = $this->db->query("SELECT sgh.inventory.id,
sgh.inventory.item_name,
sgh.inventory.invoice_number,
sgh.inventory.description,
sgh.inventory.perchase_date,
sgh.inventory.warranty_period,
sgh.inventory.warranty_end_date,
sgh.inventory.price,
sgh.inventory.qty,
sgh.company.company_name,
sgh.inventory.company_id,
sgh.inventory.employee_id,
sgh.employee.employee_name
FROM
inventory
LEFT JOIN company ON inventory.company_id=company.id
LEFT JOIN employee ON inventory.employee_id=employee.id
WHERE inventory.id='$id';
");

$inventory_row = $query->row();
return $inventory_row;
}

public function update_item($id)
{
$data['item_name'] = $this->input->post('item_name');
$data['invoice_number'] = $this->input->post('invoice_number');
$data['company_id'] = $this->input->post('company_id');
$data['employee_id'] = $this->input->post('employee_id');
$data['description'] = $this->input->post('description');
$data['perchase_date']= $this->input->post('perchase_date');
$data['warranty_period'] = $this->input->post('warranty_period');
$data['warranty_end_date'] = $this->input->post('warranty_end_date');
$data['price'] = $this->input->post('price');
$data['qty'] = $this->input->post('qty');
$this->db->where('id', $id);
$this->db->update('inventory', $data);
}

public function item_data_view($id)
{
$query = $this->db->query("SELECT sgh.inventory.id,
sgh.inventory.item_name,
sgh.inventory.invoice_number,
sgh.inventory.description,
sgh.inventory.perchase_date,
sgh.inventory.warranty_period,
sgh.inventory.warranty_end_date,
sgh.inventory.price,
sgh.inventory.qty,
sgh.company.company_name,
sgh.inventory.company_id,
sgh.inventory.employee_id,
sgh.employee.employee_name
FROM
inventory
LEFT JOIN company ON inventory.company_id=company.id
LEFT JOIN employee ON inventory.employee_id=employee.id
WHERE inventory.id='$id';");
$item_data = $query->row();
return $item_data;
}

}

Controller

<?php

Class Inventory extends CI_Controller
{


public function __construct()
{
parent:: __construct();
$this->load->model("Inventary_model");
$this->load->helper('form');
$this->load->library('form_validation');
}

public function inventory_list()
{
//Check user login information
if ($this->session->userdata('NAME'))
{

$role = $this->session->userdata('ROLE');
//Check user rights before redirect admin area
if ($role >= 1)
{
//$this->load->model("Inventary_model");
$data["inventory_data"] = $this->Inventary_model->list_item_data();

$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('inventory/inventory_list', $data);
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}else{
echo "You don't have permission to access this page";
}

} else{
echo "Please Sig-in in for enter this page";
}

}
public function create()
{
//Check user login information
if ($this->session->userdata('NAME'))
{

$role = $this->session->userdata('ROLE');
//Check user rights before redirect admin area
if ($role >= 1)
{
$this->load->helper('form');
$this->load->library('form_validation');
if ($this->input->post()) {
$this->form_validation->set_rules('item_name', 'Item Name', 'required|is_unique[inventory.item_name]');
$this->form_validation->set_rules('perchase_date', 'Purchase Date', 'required');
$this->form_validation->set_rules('warranty_period', 'Warranty Period', 'required');
$this->form_validation->set_rules('warranty_end_date', 'Warranty End Date', 'required');
$this->form_validation->set_rules('price', 'Price', 'required');
$this->form_validation->set_rules('qty', 'Quantity', 'required');

if ($this->form_validation->run() === TRUE) {
$this->load->model('Inventary_model');
$this->Inventary_model->add();
redirect('inventory/inventory_list');
}
}
//$this->load->model("Inventary_model");
$data["company"] = $this->Inventary_model->get_company();
$data["employee"] = $this->Inventary_model->get_employee();
//var_dump($em_data); die();
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('inventory/add_item', $data);
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}else{
echo "You don't have permission to access this page";
}

} else{
echo "Please Sig-in in for enter this page";
}

}

public function update_view($id)
{
if (!$id){
exit();
}else{
if ($this->session->userdata('NAME'))
{

$role = $this->session->userdata('ROLE');
//Check user rights before redirect admin area
if ($role >= 1)
{
if ($this->input->post()) {
$this->form_validation->set_rules('item_name', 'Item Name', 'required');
$this->form_validation->set_rules('perchase_date', 'Purchase Date', 'required');
$this->form_validation->set_rules('warranty_period', 'Warranty Period', 'required');
$this->form_validation->set_rules('warranty_end_date', 'Warranty End Date', 'required');
$this->form_validation->set_rules('price', 'Price', 'required');
$this->form_validation->set_rules('qty', 'Quantity', 'required');

if ($this->form_validation->run() === TRUE) {
$this->load->model('Inventary_model');
$this->Inventary_model->update_item($id);
redirect('inventory/inventory_list');
}
}
$inventory_data["row"] = $this->Inventary_model->get_item($id);
//$data["company"] = $this->Inventary_model->get_company();

if ($inventory_data["row"] == null) {
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('error_page/404');
$this->load->view('includes/footer');
$this->load->view('includes/settings');
} else {
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('inventory/update_item', $inventory_data);
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}

} else{
echo "You don't have permission to access this page";
}

} else{
echo "Please Sig-in in for enter this page";
}
}

}
public function view_item($id)
{
if ($this->session->userdata('NAME'))
{
$role = $this->session->userdata('ROLE');
if ($role >= 1)
{
$item["row"] = $this->Inventary_model->item_data_view($id);
if($item["row"] == null)
{
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('error_page/404');
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}
else
{
$this->load->view('includes/header');
$this->load->view('includes/top_header');
$this->load->view('includes/left_nav');
$this->load->view('inventory/view_item', $item);
$this->load->view('includes/footer');
$this->load->view('includes/settings');
}
}
}


}
}

View

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<h1>Update Inventory Item </h1>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box">
<div class="box-header">
<h3 class="box-title">Update <?php echo $row->item_name ?> Details</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<div class="row">
<div class="col-md-12">
<span class="text-danger"><?php echo validation_errors() ?></span>
<form action="<?=base_url()?>index.php/inventory/update_view/<?=$row->id?>" method="post">
<div class="box-body">
<div class="form-group">
<label>Item Name</label>
<input type="text" class="form-control" name="item_name" value="<?php echo $row->item_name ?>">
</div>
<div class="form-group">
<label>Invoice Number</label>
<input type="text" class="form-control" name="invoice_number" value="<?php echo $row->invoice_number ?>">
</div>
<!--
<div class="form-group">
<label>Select a Company</label>
<select class="form-control select2" style="width: 100%;" name="company_id" >
<option value="<?php echo $row->company_id ?>" ><?php echo $row->company_name ?></option>
</select>
</div>
-->
<!--<input type="hidden" name="<?php echo $row->company_id ?> ?>" value="<?php $row->company_id ?> ?>">-->
<div class="form-group">
<label>Select a Company</label>
<select class="form-control select2" style="width: 100%;" name="company_id" >
<option value="<?php echo $row->company_id ?>" ><?php echo $row->company_name ?></option>
<?php
$company_data = $this->Inventary_model->get_company();

foreach ($company_data as $name){
if ($row->company_id != $name->id ){
?>
<option value="<?php echo $name->id ?>" ><?php echo $name->company_name ?></option>
<?php
}
}
?>
</select>
</div>

<div class="form-group">
<label>Select a Item User</label>
<select class="form-control select2" style="width: 100%;" name="employee_id" >
<option value="<?php echo $row->employee_id ?>" ><?php echo $row->employee_name ?></option>
<?php
$employee_data = $this->Inventary_model->get_employee();
foreach ($employee_data as $employee){
if ($row->employee_id != $employee->id) {
?>
<option value="<?php echo $employee->id ?>"><?php echo $employee->employee_name ?></option>
<?php
}
}
?>

</select>
</div>

<div class="form-group">
<label for="exampleInputPassword1">Description</label>
<script src="<?php echo base_url(); ?>assets/bower_components/ckeditor/ckeditor.js"></script>
<textarea id="editor1" name="description" rows="10" cols="80">
<?php echo $row->description ?>
</textarea>
<script>
CKEDITOR.replace( 'editor1' );
</script>
</div>
<div class="form-group">
<label>Purchase Date</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="text" value="<?php echo $row->perchase_date ?>" name="perchase_date" class="form-control" data-inputmask="'alias': 'dd/mm/yyyy'" data-mask >
</div>
</div>
<div class="form-group">
<label>Warranty Period</label>
<input type="text" class="form-control" name="warranty_period" value="<?php echo $row->warranty_period ?>">
</div>
<div
<div class="form-group">
<label>Warranty End Date</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="text" value="<?php echo $row->warranty_end_date ?>" name="warranty_end_date" class="form-control" data-inputmask="'alias': 'dd/mm/yyyy'" data-mask>
</div>
</div>

<div class="form-group">
<label>Price</label>
<div class="input-group">
<div class="input-group-addon">
<span>Rs. </span>
</div>
<input type="text" class="form-control" name="price" value="<?php echo $row->price?>">
</div>
</div>
<div class="form-group">
<label>Quantity</label>
<input type="text" class="form-control" name="qty" value="<?php echo $row->qty?>">
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<div class="row">
<div class="col-md-3">

</div>
<div class="col-md-3">
<button type="submit" class="btn btn-info btn-lg" >Save</button>

</div>
</form>
<div class="col-md-3">

<a href="<?=base_url()?>index.php/inventory/inventory_list/" class="btn btn-info btn-lg" >Cancel</a>
</div>
<div class="col-md-3">

</div>
</div>
</div>

</div>

</div>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->

Same Error still i am getting. Please help me..
Reply

#5
You aren't calling view_profile() from there. I guess you click on a link?
How does that URL look like?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.