Reputation: 441
i want when there is value "flashdata" echo id='error_text'
with $this>session>flashdata('error')
. how is it?
this code have error:
<?php
isset($this->session->flashdata('error'))
{
"<div id='error_text'>" . $this->session->flashdata('error') . "</div>"}
?>
error:
Fatal error: Can't use method return value in write context in D:\xampp\htdocs\mehdi\system\core\Loader.php(679) : eval()'d code on line 2
if use of this:
#error_text {
background-color: #000000;
}
<div id="error_text"><?=$this->session->flashdata('error');?></div>
if $this->session->flashdata('error')
not show message background it always is black (#error_text{background-color: #000000;}
).
EDIT:
in controller:
if ($this->db->count_all($this->_table) == 0) {
$this->session->set_flashdata('error', 'Error have.');
$error = isset($this->session->flashdata('error')) ? $this->session->flashdata('error') : FALSE; // Line 36
redirect('admin/accommodation/insert');
} else {
return 0;
}
in view:
<?php if($error){"<div id='error_text'>".$this->session->flashdata('error')."</div>"}?>
new error:
Fatal error: Can't use method return value in write context in D:\xampp\htdocs\Siran-mehdi\application\controllers\admin\accommodation.php on line 36
Upvotes: 1
Views: 3156
Reputation: 1635
You need to transfer the flashdata into variable at the first place. And do that in your controller, then send it to view. Its better to separate logic from presentation.
if ($this->db->count_all($this->_table) == 0)
{
$this->session->set_flashdata('error', 'Error have.');
// You doesn't need that here...
// $error = isset($this->session->flashdata('error')) ? $this->session->flashdata('error') : FALSE; // Line 36
redirect('admin/accommodation/insert');
}
else
{
return 0;
}
// Then for validate, in 'admin/accommodation/insert'
$error = $this->session->flashdata('error');
$data = array();
//...
$data['error'] = $error;
$this->load->view('someview',$data);
// And in your view file
<?php if($error) : ?>
<div id="error_text"><?php echo $error ?></div>
<?php endif; ?>
Upvotes: 2