CodeIgniter Forums
is any global way pass session vars to views or THE ONLY WAY IS when pass vars to vie - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: is any global way pass session vars to views or THE ONLY WAY IS when pass vars to vie (/thread-69929.html)



is any global way pass session vars to views or THE ONLY WAY IS when pass vars to vie - lsepolis123 - 01-31-2018

Code:
  <h2>Welcome Back, <?php echo $this->session->userdata('username'); ?>!</h2>

1    3.1.7
How this session var passed to view and get accessed directly from $this->session obj? is any global way pass session vars to views or THE ONLY WAY IS when pass vars to view from controller like $data below????

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

2   3.1.7
API JSON requests in codeigniter like this https://tech.yandex.com/translate/doc/dg/reference/translate-docpage/

in what page of manual exist more info about codeigniter json requests????


RE: is any global way pass session vars to views or THE ONLY WAY IS when pass vars to vie - XtreemDeveloper - 01-31-2018

You can load session library in autoload file after that no need for passing the parameter in view file.
You can directly get the session value in view file.


RE: is any global way pass session vars to views or THE ONLY WAY IS when pass vars to vie - InsiteFX - 01-31-2018

You can pass variables to a view using.

PHP Code:
$this->load->vars($data); 



RE: is any global way pass session vars to views or THE ONLY WAY IS when pass vars to vie - dave friend - 01-31-2018

(01-31-2018, 06:43 AM)lsepolis123 Wrote: in what page of manual exist more info about codeigniter json requests????

Other than the input class method is_ajax_request() (Docs HERE) there really isn't any.

There isn't much you need to know other than the URL from the JavaScript should point to a controller/method. That controller/method needs to  echo back the kind of data that was defined in the ajax call. If that data is JSON then usually a call to json_encode($data); happens somewhere along the line.

There are lots of examples out in the wild on how to "do" AJAX with CI.

One library that I found very useful is ThingEngineer/Codeigniter-jQuery-Ajax.