I want to pass $data
from the controller named poll
to the results_view
however I am getting an undefined variable error.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Poll extends CI_Controller { public function __construct() { parent::__construct(); $this->load->database(); $this->load->helper('form'); } public function index() { $this->load->view('poll_view',$data); } public function vote() { echo "Voting Successfull"; $this->db->insert('votes',$_POST); } public function results() { echo "These are the results"; //$query = $this->db->get('votes'); $data = "hello"; $this->load->view('results_view', $data); } }
Results_view.php
<html> <?php echo $data; ?> </html>
click(function(){ var id_thang = $(this). attr('value'); $. ajax({ url: baseUrl+'/Home/getImage', dataType: 'json', type: 'POST', data: {id_thang: id_thang}, }). done(function(result) { console.
$data=array($var1,$var2); $this->load->view('myview',$data);
call first controller from first view and pass form data to second view. On second view you can create hidden inputs and set their values from controller data. Now submit the second form to final controller and you will get all the values of both form. Hope this helps you.
Since a controller writes either to view or model - you'd pass variables to view via controller. $model = new Model(); $view = new View($model); $controller = new Controller($view); // This will assign variables to view $controller->indexAction(); echo $view->render();
$data
should be an array or an object: http://codeigniter.com/user_guide/general/views.html
$data = array( 'title' => 'My Title', 'heading' => 'My Heading', 'message' => 'My Message' ); $this->load->view('results_view', $data);
results_view.php
<html> <?php //Access them like so echo $title.$heading.$message; ?> </html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With