0

Why do I pass a variable name when calling a view file?

For example: $this->load->view("{$viewData->viewFolder}/{$viewData->subViewFolder}/index", $viewData);

Why we writing $viewData at a last code line?

Roman Pokrovskij
  • 9,449
  • 21
  • 87
  • 142

2 Answers2

2

no need to load variable:

$data['view'] = 'folername/view_file_namae';
$this->load->view('you can call common file for header/footer here', $data);
PHP Geek
  • 3,949
  • 1
  • 16
  • 32
0

To pass a variable name to view file,

$this->data['anyname'] = $variable;
$this->load->view('viewfilename',$this->data);

and In your view file name, access your passed data as echo $anyname;. You can pass a variable or an array as you want.

If you want to append a variable name to a view file, you can use redirect() function.

Source : https://www.codeigniter.com/user_guide/helpers/url_helper.html#redirect

e.g.

redirect('home/category/'.$variable, 'refresh');
redirect('home/category/subcategory/'.$variable, 'refresh');
G_real
  • 1,137
  • 1
  • 18
  • 28