0
Severity: Notice

Message: Undefined variable: blog_data

Filename: views/savedata.php

Line Number: 4

Backtrace:

File: /Applications/MAMP/htdocs/success_story_ci/application/views/savedata.php
Line: 4
Function: _error_handler

File: /Applications/MAMP/htdocs/success_story_ci/application/controllers/Story.php
Line: 31
Function: view

File: /Applications/MAMP/htdocs/success_story_ci/index.php
Line: 315
Function: require_once

    public function savedata(){

        if(!empty($this->input->post())){

            $data = array(
                          'cluster_det' => $this->input->post('Clust_det'),
                          'need_of_activity' => $this->input->post('need_of_the_activity'),
                          'intervention' => $this->input->post('intervention'),
                          'impact' => $this->input->post('impact'),
                          'key_stakeholders' => $this->input->post('Key_stakeholders'),
                          'beneficiaries' => $this->input->post('beneficiaries'),
                          'activity_det' => $this->input->post('activity_det'),
                          'reference_contact' => $this->input->post('reference_contact'),
                          'image' => 'imageaddress',//$this->input->post('image')
                          'title' => $this->input->post('title')
                          );

            $res = $this->db->insert('blog', $data);
            $id = $this->db->insert_id();
            $this->db->select('*');
            $this->db->from('blog');
            $this->db->where('id', $id);
            $blog_data = $this->db->get();

            $this->load->view('savedata', $blog_data);

            echo 'data saved';
            return true;
        }

    }

    public function index()
    {
        $this->load->view('savedata');
    }

the above code is to pass a variable to the view ie the data insert command and the id from the last record so the last record is passed as variable $blog_data to view. Also required to send the variable at the view with codeigniter to display the blog entry.

4 Answers 4

1

Change

$blog_data = $this->db->get();

to

$blog_data['blog_data'] = $this->db->get()->result_array();

or

$blog_data['blog_data'] = $this->db->get()->row_array();

to get the data.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this, To pass variable to view
Controller:

$data = array();
$data['blog_data'] = $blog_data;//from your model or db source
$this->load->view('savedata', $blog_data);

View

<?php echo'<pre>';print_r($blog_data);die; ?>

Comments

0

Remove this

$blog_data = $this->db->get()

and place this code

$blog_data['blog_data'] = $this->db->get()->row_array();

1 Comment

this is to get data from db but i wanna send data from controller to view, read question properly.
0

when you are in your modal in the end you need your data in array format so we use

In modal:-
$query = $this->db->get('table_name');
    $result_var = $query->result_array();
    return $result_var;
In Controller :-
$this->modal->('modal_name');
$variable_name['For_view_pass_variable_name'] = $this->modal_name->modal_function_name;

try to use MVC pattren it will be helpful for you.

1 Comment

i require to use only controller to send data from controller to view. but thanks.

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.