Tuesday, 10 October 2017

php - problem in show message set_flashdata with div in codeigniter?

itemprop="text">

i want when there is value "flashdata"
echo id='error_text' with
$this>session>flashdata('error'). how is it? />this code have error:




isset($this->session->flashdata('error'))

{

"
" .
$this->session->flashdata('error') . "
"}

?>


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;
}
id="error_text">session->flashdata('error');?>




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:



            id='error_text'>".$this->session->flashdata('error')."
"}?>


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



class="post-text" itemprop="text">
class="normal">Answer



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

id="error_text">

?>

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...