CodeIgniter Forums
[Solved] Loading view as $string not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: [Solved] Loading view as $string not working (/thread-60581.html)

Pages: 1 2


[Solved] Loading view as $string not working - El Forum - 05-01-2014

[eluser]riwakawd[/eluser]
I read the codeigniter user guide but it said I could load view as as $string in controller.

I have done that but footer is at top. I tried adding return but nothing. Footer still at top. Need to added return but don't know where.

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {

public function index() {
  $data['header'] = $this->load->view('template/common/header', true);
  $data['footer'] =  $this->load->view('template/common/footer', true);

  return $this->load->view('template/common/login', $data);
}
}



[Solved] Loading view as $string not working - El Forum - 05-01-2014

[eluser]CroNiX[/eluser]
Check the userguide. Your parameters are wrong for the header/footer views. The TRUE should be the 3rd parameter.


[Solved] Loading view as $string not working - El Forum - 05-01-2014

[eluser]riwakawd[/eluser]
[quote author="CroNiX" date="1398959813"]Check the userguide. Your parameters are wrong for the header/footer views.[/quote]

you think should be false?


[Solved] Loading view as $string not working - El Forum - 05-01-2014

[eluser]CroNiX[/eluser]
No, but it goes in the 3rd parameter, not 2nd. Data is for 2nd parameter. If you're not sending data to the view, use an empty array there, or NULL would probably work.


[Solved] Loading view as $string not working - El Forum - 05-01-2014

[eluser]CroNiX[/eluser]
You also don't need to return the login view


[Solved] Loading view as $string not working - El Forum - 05-01-2014

[eluser]riwakawd[/eluser]
[quote author="CroNiX" date="1398960114"]No, but it goes in the 3rd parameter, not 2nd. Data is for 2nd parameter. If you're not sending data to the view, use an empty array there, or NULL would probably work.[/quote]

Tried null and put true in 3rd view only footer now showing

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends MX_Controller {

public function index() {
  $this->setOutput();
}

function setOutput() {
  //$data['title'] = "Administration";

  $data['header'] = $this->load->view('template/common/header');
  $data['footer'] =  $this->load->view('template/common/footer');

  $this->load->view('template/common/login', true);
}
}



[Solved] Loading view as $string not working - El Forum - 05-01-2014

[eluser]CroNiX[/eluser]
Code:
public function index() {
  $data['header'] = $this->load->view('template/common/header', array(), true);
  $data['footer'] =  $this->load->view('template/common/footer', array(), true);

  $this->load->view('template/common/login', $data);
}

In the login view,
Code:
echo $header;
echo $footer;
where you want them to show up


[Solved] Loading view as $string not working - El Forum - 05-01-2014

[eluser]riwakawd[/eluser]
[quote author="CroNiX" date="1398960444"]
Code:
public function index() {
  $data['header'] = $this->load->view('template/common/header', array(), true);
  $data['footer'] =  $this->load->view('template/common/footer', array(), true);

  $this->load->view('template/common/login', $data);
}

In the login view,
Code:
echo $header;
echo $footer;
where you want them to show up[/quote]

Works now. Cheers why need array(),


[Solved] Loading view as $string not working - El Forum - 05-01-2014

[eluser]CroNiX[/eluser]
Because the data portion is the 2nd parameter of load::view(), and whether to return the view is the 3rd. So you have to have something there even if you're not sending actual data to that view partial in order to have a 3rd parameter.
From userguide:
Code:
$this->load->view('file_name', $data, true/false)



[Solved] Loading view as $string not working - El Forum - 05-01-2014

[eluser]Tim Brownlaw[/eluser]
Yes, when in doubt, read the userguide!

To Paraphrase what Cronix has stated - It's how it was written to work!

And can you mark this as solved!