0

我有一个thank_you.php 文件,其中只包含字符串“Thank you”。格式化为成功/绿色。

我想在网站的特定区域显示此文本,但不知道如何去做。在我的主视图文件中,我添加了以下行:

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

“提交”按钮旁边。

在我的控制器中,我有一个函数,一旦被调用,它就会显示视图文件“thank_you.php”。

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

我的模板文件中有标准的 $alert、$content、$main 等区域,但是如何将此视图文件回显到另一个视图文件中?我还需要其他方法吗?

4

4 回答 4

1

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!

于 2013-07-15T21:53:50.570 回答
0

在控制器中,您希望将视图输出缓冲到变量,并将变量传递给模板。view 方法中的第三个参数允许您将视图输出作为字符串返回。

$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

请参阅本页底部:http ://ellislab.com/codeigniter/user-guide/general/views.html

于 2013-07-15T20:30:22.697 回答
0

1-你可以这样传递:

 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>
于 2013-07-16T02:46:49.067 回答
0

如果要在另一个视图文件中加载一个视图文件。

只需键入

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

我希望它能解决你的问题。


编辑:

或者,如果您想在对 Button 执行某些操作后加载另一个视图。您可以将按钮重定向到该控制器。在那里你可以写下上面的行。

如果它是一个锚按钮就放<a class="BtnClass" href="ControllerPathHere">Submit</a>

如果您正在使用一些模板库,请详细说明。

于 2013-07-15T19:31:26.883 回答