Welcome Guest, Not a member yet? Register   Sign In
[Solved] Loading view as $string not working
#1

[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);
}
}
#2

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

[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?
#4

[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.
#5

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

[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);
}
}
#7

[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
#8

[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(),
#9

[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)
#10

[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!




Theme © iAndrew 2016 - Forum software by © MyBB