开发者

problem in show message set_flashdata with div in codeigniter?

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 开发者_Python百科line 36


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; ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜