Pass array from controller to view - Codeigniter

how to pass data from view to controller in codeigniter
how to pass multiple data from controller to view in codeigniter
how to pass id from view to controller in codeigniter
array in codeigniter
how to pass array from controller to model in codeigniter
how to get value from array in codeigniter
how to get array value in codeigniter controller
how to pass id in base_url in codeigniter

I tried to print the array in the controller, before passing it to a view and this is the output

Array ( [annunci] => Array ( [0] => stdClass Object ( [EmailDatore] => [Nome] => asdasd [Cognome] => asdas [IdAnnuncio] => 9 [Titolo] => sfsdfdsfshrea [Testo] => agrefdgdagdfg [Categoria] => [Sede] => [TipoContratto] => [Add_Date] => [Drop_Date] => ) 
[1] => stdClass Object ( [EmailDatore] => [Nome] => asdasd [Cognome] => asdas [IdAnnuncio] => 10 [Titolo] => fafa [Testo] => fafaerea asdasdas dafasfd [Categoria] => [Sede] => [TipoContratto] => [Add_Date] => [Drop_Date] => ) ) )

I get the array from this method in my maincontroller

 public function get_annunci(){


I would like to pass this array to a view and then read the data. So i rewrite my method like this

public function get_annunci(){

In main view i have this

<div class="tab-pane active" id="annunci">

This is my error

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: annunci

Filename: views/tab_annunci_view.php

Line Number: 4
public function get_annunci(){

You're passing the array but you aren't passing annunci as a variable.

How to Pass Data From Controller to View in CodeIgniter, Do you mean: how to submit a form containing an array, or how to make an ajax request and posting an array, or something else? and then  Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

This is because you have not defined $annunci and made it available to the view. You need to load it to the view first by


$data['id'] = $yourArray;
$this->load->view('your_view_file', $data);


 <?php print_r($id); ?> //prints $yourArray

how to pass array from view to controller, Using <form > to pass data from view to controller. View The $this->input->post​() method returns an Associative array of submitted values. Pass Data Between View and Controller in CodeIgniter HTML form is one of the common elements within the webpage which allows the user to input data and submit it for processing. The data is also passed by URL which is good for limited and less sensitive information.

public function index()

I hope this is work. if you handle n number of records use this method.

Pass Data Between View and Controller in CodeIgniter, <?php class MY_Controller extends CI_Controller { //Get user data for all controllers public $users = array(); function __construct()  In view we pass array and the key of array will automatically become variable and will be made available to you by codeigniter, we can't simply pass variables to view we need to pass array. Below is your code

(Change $query to $query ['annunci']) OK, the $query is an array already, then just change the view file to 'tab_annunci_view'


public function get_annunci(){

CodeIgniter. How to pass data from Core controller to view without , So far, I've added a function into controllers\single_pages\profile.php with a it into a return() (or whatever is needed) to pass it to the view.php. codeigniter: pass array from controller to view. Ask Question Browse other questions tagged php arrays codeigniter view controller or ask your own question.

Get a data array from controller into view.php? (Profiles single page , You'll recall that the last line of the index view in our Todos controller is: Up to now, we previously only called load->view passing it one parameter — the is that we're passing the load->view function a second parameter: our $data array. A controller often comprises of several functions and often the module’s logic demands passing data between the various functions of the Controller. This is a common enough scenario in many Codeigniter projects. In this tutorial, I will demonstrate how you could pass data between two functions within the same Controller in CodeIgniter. In

Loading and Displaying Data in a CodeIgniter View – Self-Taught , I am trying to create my user module in codeigniter and can't figure out how to pass How do I pass variables from a model to a controller to be used on a view in Or should I be putting them in an array and then passing the array ( still not  Passing the Array from Controller to View Add the following code in your controller file The objects are shown as an Arrow(->) and arrays as a Brick. You can easily access any object using the (->) arrow and an array with the Brick [‘..’].

How do I pass variables from a model to a controller to be used on a , Our Controllers In Codeigniter article gave an example of a controller named Sayhi . Recall that You can pass data in the form of an array or object to the view. I am building a store front with CodeIgniter where list of items from the database is displayed with a checkbox in the View. The user is to select items and enter their quantity. When the user Clic

  • Your error shows that you are trying to load views/tab_annunci_view.php but your code says main_view.
  • Every single view in my application loads with this line: $this->load->view('templates/template',$data); What he's calling in the controller has nothing to do with the actual view file name at that line.
  • Print out in the first line shows that he has already created index annunci.
  • I edited the answer you just have to change the view file to 'tab_annunci_view'.
  • Why would you make that edit? He's quite obviously calling the right view since he's getting the undefined variable error. Otherwise he'd get a 404.
  • @Rick Clader he said 'Print out in the first line shows that he has already created index' what means $query is an array
  • Look at the error he's receiving, line 4 is where he tries to output annunci, therefore he has to be loading the right view. See my comment on his original post, what it says in that line does not have to match the actual view file name.