Welcome Guest, Not a member yet? Register   Sign In
can you load a view within a view
#1

[eluser]bill19[/eluser]
Hello,

I have an html form which I have saved in a view called page1.php . I have a form ( an html fragment ) in the view form.php.

Is there a way to insert form.php into page.php, and have it be presented as valid html?

Thanks,

Bill
#2

[eluser]TWP Marketing[/eluser]
Yes. but it is better to do this in your controller, using the second parameter of the loader function
for example, in the controller
Code:
...
  // store standard site page header/nav/footer as html strings (not sent directory to browser
  $data['header']     = $this->load->view('page_header',$this->view_data,TRUE);
  $data['navigation'] = $this->load->view('page_navigation',$this->view_data,TRUE);
  $data['footer']     = $this->load->view('page_footer',$this->view_data,TRUE);
...
  $data['form'] = $this->load->view('my_form',$this->view_data,TRUE);
   // send the stored html strings to the browser
  $this->load->view('page',$data);

Notice the second parameter in the first three calls to load->view().

In the view named page.php:
Code:
...
echo $header;
echo $navigation;
...
echo $form;  // this is your form html
...
echo $footer;
#3

[eluser]PhilTem[/eluser]
You can, but actually should not, have this code in your page.php

Code:
// ... All your previous code

$this->load->view('form1');

// ... All your follow up code
#4

[eluser]skunkbad[/eluser]
[quote author="PhilTem" date="1343154126"]You can, but actually should not, have this code in your page.php

Code:
// ... All your previous code

$this->load->view('form1');

// ... All your follow up code
[/quote]

I think you should be clear who you are replying to, what you should not do, and why you should not do it.




Theme © iAndrew 2016 - Forum software by © MyBB