Codeigniter Session set and Retrieve multidimensional array
Contents
In this Post We Will Explain About is Codeigniter Session set and Retrieve multidimensional array With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Saving Array to a Session and Retrieve it, CodeIgniterExample
In this post we will show you Best way to implement Storing multidimensional array in session variable, hear for Codeigniter echo session Multidimensional Array variablewith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
codeigniter set multidimensional array in session
$products['categoty']=$this->Qmodel->get_answers(); $data= array( 'pname' => $this->input->post('pname'), 'is_stock'=> 1, 'products' => $products['categoty'] ); $this->session->set_userdata($data); $token_from_session = $this->session->userdata('products'); //return simple get categoty $products['categoty'] array
Codeigniter echo session Multidimensional Array variable
$get_sessiondata = $this->session->all_userdata(); echo $get_sessiondata['product_data']['uniq']; // 6 $product_data = $this->session->userdata('product_data'); echo $product_data['uniq']; /// 5 $ci_Auth = $this->session->userdata('ci_Auth'); echo $ci_Auth['user_id']; /// 5 or echo $this->session->userdata('last_activity');
PHP Code to simple set Session variable
session_start(); $toons=array("Donald", "Goofy", "Mickey"); $spouses=array("Daisy", "none", "Minnie"); $_SESSION['families']=array($tunes, $spouses);
Example 1 : Passing Multidimensional array to Codeigniter view
Array ( [products] => Array ( [img_id] => 2 [img_name] => livedsp.jpg [url] => https://www.pakainfo.com/products/livedsp.jpg [cr_date] => 2018-01-29 ) [a2] => Array ( [img_id] => 1 [img_name] => livedsp.jpg [url] => https://www.pakainfo.com/products/livedsp.jpg [cr_date] => 2018-01-29 ) )
images_model:
<?php if ( ! defined('BASEPATH')) exit('No any direct script help to access allowed'); class Images_model extends CI_Model { public function get_last_ten(){ $q = $this->db->query("SELECT * FROM products ORDER BY img_id DESC LIMIT 20"); $data=1; foreach ($q->result() as $results) { $get_row_img['a'.$data]['img_id'] = $results->img_id; $get_row_img['a'.$data]['img_name'] = $results->img_name; $get_row_img['a'.$data]['url'] = $results->url; $get_row_img['a'.$data]['cr_date'] = $results->uploaded_date; $data++; } return $get_row_img; } }
Controller code:
<?php if ( ! defined('BASEPATH')) exit('No any direct all the script access allowed'); class Welcome_live24u extends CI_Controller { public function index() { $get_userData = $this->session->userdata('email'); if(empty($get_userData)){ $this->load->view('head_view'); $this->load->view('welcome_message'); $this->load->view('foot_view'); } else{ $this->load->model('images_model'); $get_row_img = $this->images_model->get_last_ten(); print_r($get_row_img); $this->load->view('head_view'); $this->load->view('logged_in_message', $get_row_img); $this->load->view('foot_view'); } } }
View Code:
<h1>Welcome_live24u <?php echo $this->session->userdata('email'); ?> to live24u Picture Site </h1> <div id="body"> <p>Thank you for all data the coming to see live24u photos.</p> <p> <?php foreach($products as $results){ var_dump($results); } ?> </p> </div>
I hope you have Got What is Passing Multidimensional array to Codeigniter view And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.
I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I’m a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.