Question

I have a thank_you.php file that simply contains the string "Thank you." formatted in a successful / green color.

I'm wanting to display this text on a specific region of the site, but not sure how to go about it. Within my main view file, I added the line:

<?php $this->template->add_region('success'); ?>

next to the "Submit" button.

Within my controller, I have a function that should, once called, display the view file "thank_you.php".

function greeter_thank_you() {
$this->template->write_view('success', 'thank_you.php');
}

I have the standard $alert, $content, $main, etc... regions within my Template file, but how do I echo this view file onto another view file? Is there some other way I need to go about it?

Was it helpful?

Solution

It seems you are using Collin Williams' CI Template library.

As far as I know, you can't define a region inside another one, so it is better to send the value of the internal region (which you called it success) into the main region.

  • If you are using $this->template->write(); method to write content to the main region:

Get the content of thank_you view file by using $this->load->view('thank_you', '', TRUE); and place it somewhere inside the second parameter of write().

  • If you are using $this->template->write_view() method:

Use the following:

$data = array(
    'foo'     => 'bar',
    'baz'     => 'qux',
    'success' => $this->load->view('thank_you', '', TRUE)
);

$this->template->write_view('main', 'main_region_view_file_here', $data/*, TRUE*/);

And add the following inside the view file of the main region:

if (! empty($success)) {
    echo $success;
}

I don't have any experience with Collin Williams' Template library, but I think this might do the trick.

By the way, If you had any problem, I'm all ears!

OTHER TIPS

if you want to to load one view file within another view file.

Just type

$this->load->view('FolderPath/FileNameHere');

I Hope it solves your Problem.


Edit:

Or if You are Tying to Load another View after Performing some action on Button. You can redirect your button to that controller. and there you can write the above line.

if it is a anchor Button just put <a class="BtnClass" href="ControllerPathHere">Submit</a>

and if you are using some templates Library Please tell more about it.

In the controller, you want to buffer the view output to a variable, and pass the variables to the template. The third parameter in the view method allows you to return the view output as a string.

$viewData = array(
    'main' => $this->load->view('thank_you.php', '', true)
);

$this->load->view('template.php', $viewData);

// access the main template data with $main in template.php

See the bottom of this page: http://ellislab.com/codeigniter/user-guide/general/views.html

1-You can pass it like this:

 function greeter_thank_you()
 {
       $data = array();
       $thank_page = $this->load->view('thank_you');
       $data['thank_you'] = $thank_page;

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


inside your main page

 <html>
  <body>
  <div id='thank'>
    <?=$thank_you?>
  </div>
  <!--The rest of your codes-->
 </body>
</html>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top