如何在codeigniter中显示消息?

Har*_*jan 3 php message codeigniter

我想在重定向链接上显示内容更新的成功消息.这是我的控制器代码: -

public function add_content()
        {
        $this->load->helper('url');
    $id=$this->input->post('id');
        $content=$this->input->post('content');
        $title=$this->input->post('title');
        $this->load->model('admin/contentmodel');
    $status=$this->contentmodel->addcontent($id,$title,$content);
        if($status==1)
           {
            $this->session->set_flashdata("message","<font class='success'>Content Successfully Updated..!!</font>");
            redirect('admin/login/dash');
            }
        else
          {
           $this->session->set_flashdata("message","<font class='success'>Content Not Updated..!!</font>");
           redirect('admin/content/home');
          }
        }
Run Code Online (Sandbox Code Playgroud)

我的内容已成功更新,现在我想在特定的重定向链接上向用户显示该消息.因为我在上面的代码中设置了消息:

$this->session->set_flashdata("message","<font class='success'>Content Successfully Updated..!!</font>");
Run Code Online (Sandbox Code Playgroud)

所以,你们可以让我知道我哪里出错了,我怎么能在视图上显示错误信息?当我的重定向转到控制器 - >而不是在view.so我如何从控制器 - >视图流出我的错误MSG .提前致谢.

Ser*_*sky 7

打开application/config/config.php并编辑该行:

$config['encryption_key'] = '';
Run Code Online (Sandbox Code Playgroud)

通过向字符串添加一些随机值

$config['encryption_key'] = 'q0231sz!!1@asd';
Run Code Online (Sandbox Code Playgroud)

之后,当您设置消息时

$this->session->set_flashdata('key', 'value');
Run Code Online (Sandbox Code Playgroud)

在您的视图文件中只需回显

echo $this->session->flashdata('key');
Run Code Online (Sandbox Code Playgroud)

请注意,这不会'value'在此负载上回显您,但在刷新页面后将回显它

$this->session->set_flashdata('mykey', 'testing');
echo $this->session->flashdata('mykey'); // will echo '' (nothing)
Run Code Online (Sandbox Code Playgroud)