Reputation: 166
I think the code that I run is correct, but a moment in the run even appear error 'Call to undefined function delete_cookie ()'
Please for correction :)
in Controller Product_Ref.php
public function index()
{
$ref = $this->input->get('id');
$getIdOrder = $this->product_model->getIdOrder($ref);
if ($getIdOrder) {
$this->load->helper('cookie');
$cookie = array(
'name' => 'refProductcookie',
'value' => $ref,
'expire' => '43200'
);
$this->input->set_cookie($cookie);
echo get_cookie('refProductcookie').'<br>';
}else {
echo "Sorry this product has not been registered yet";
delete_cookie('refProductcookie');
}
}
Upvotes: 2
Views: 3621
Reputation: 1729
problem is in else statement didnt load cookie helper, add this line in else statement or better top of if $this->load->helper('cookie');
Upvotes: 1
Reputation: 54831
You need to load helper cookie
for both of your if-else
-cases:
// load BEFORE `if`
$this->load->helper('cookie');
if ($getIdOrder) {
$cookie = array(
'name' => 'refProductcookie',
'value' => $ref,
'expire' => '43200'
);
$this->input->set_cookie($cookie);
echo get_cookie('refProductcookie').'<br>';
}else {
echo "Sorry this product has not been registered yet";
delete_cookie('refProductcookie');
}
Upvotes: 5