[eluser]Unknown[/eluser]
I have a seemingly simple controller method that inserts a database record, and moves to an edit method:
Code:
public function create_ca($ca_type_id = 0)
{
$this->check_edit(); // LDAP login check
if ($ca_type_id == 0) $ca_type_id = $this->uri->segment(3) + 0;
$ca_id = $this->ca->create_ca($ca_type_id);
$this->edit_ca($ca_id);
}
The ca model has a create_ca method as well:
Code:
public function create_ca($ca_type_id, $problem = "")
{
if ($ca_type_id > 0) {
$username = $this->login->get_username();
$sql = "INSERT INTO a2db.CorrectiveActions (CATypeID, username, dateissued, problem) VALUES (?, ?, now(), ?)";
$this->db->query($sql, array($ca_type_id, $username, $problem));
$ca_id = $this->db->insert_id();
$sql = "INSERT INTO cas (ca_id, ca_type_id, creator, date_created, problem) VALUES (?, ?, ?, now(), ?)";
$this->db->query($sql, array($ca_id, $ca_type_id, $username, $problem));
return $ca_id;
}
}
The controller method is triggered with a url ending with
/ca/create_ca/4.
The funny behavior is that the create_ca in the controller appears to be triggered three times.
While debugging the behavior, I noticed that if I inserted an
echo somewhere in the model method, the behavior stopped.
I've been able to circumvent the behavior with an
if statement in the model because to 2 secondary iterations were called with a $ca_type_id = 0.
Which is strange, because it should be overriding a 0 value with a uri segment in the controller... and the actual uri segment certainly shouldn't have changed.
Does this make sense?