0

I have this function in my controller :

public function simpan() {
    $this->load->library('form_validation');
    // field name, error message, validation rules
    $this->form_validation->set_rules('name', 'User Name', 'trim|required|min_length[4]|xss_clean');
    $this->form_validation->set_rules('email', 'Your Email', 'trim|required|valid_email');
    $this->form_validation->set_rules('message', 'Your Message', 'trim|required');

    if ($this->form_validation->run() == FALSE) {
        $data['msg_save'] = "data not saved";
        $this->load->view("v_bukutamu, $data");
    } else {
        $this->m_bukutamu->simpan();
        $data['msg_save'] = "data saved";
        $this->load->view("v_bukutamu, $data");
    }
}

And this line to parsing varible $msg_save in View :

<p><?php if (isset($msg_save)) echo $msg_save; ?></p>

The data was successful saved to database, but it's give me this error message :

Message: Array to string conversion

I just want to show the successful or failed message with the same view. Does anyone have any idea what should I change in my script?

1
  • Antoher of my typos.. Thanks all.. Commented Jan 16, 2014 at 6:45

3 Answers 3

2

The Correct way of passing variable on views page is given below

$this->load->view("message", $data);

The problem in your code was that you were using it in

$this->load->view("v_bukutamu, $data");

this way whereas you should use it in way given below

$this->load->view("v_bukutamu", $data);
Sign up to request clarification or add additional context in comments.

Comments

2

You should use

$this->load->view("v_bukutamu", $data);

instead of

$this->load->view("v_bukutamu, $data");

To load a particular view we use $this->load->view('name'); where name is the name of the view file without php extension.

Data is passed from the controller to the view by way of an array or an object in the second parameter of the view loading function. eg :

$data = array(
               'title' => 'My Title',
               'heading' => 'My Heading',
               'message' => 'My Message'
          );

$this->load->view('blogview', $data);

more info here

Comments

1

Simply change the

$this->load->view("v_bukutamu, $data");

To

$this->load->view('v_bukutamu', $data);

And use single quotes instead of double quotes

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.