Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter中的模板插件_Php_Codeigniter - Fatal编程技术网

Php Codeigniter中的模板插件

Php Codeigniter中的模板插件,php,codeigniter,Php,Codeigniter,我一直在使用和研究Collin Williams模板插件,我已经在CI的论坛上发布了这个问题,但我认为最后一篇文章是去年发布的,也许它没有被Collin或wat监控,但我想我只能在这里发布,也许你们能帮上忙 CI论坛原创帖子 你好,科林 I’ve been studying your template plugin lately, as i was following your guide, i came across this line of code $data = array('nam

我一直在使用和研究Collin Williams模板插件,我已经在CI的论坛上发布了这个问题,但我认为最后一篇文章是去年发布的,也许它没有被Collin或wat监控,但我想我只能在这里发布,也许你们能帮上忙

CI论坛原创帖子

你好,科林

I’ve been studying your template plugin lately, as i was following your guide, 
i came across this line of code

$data = array('name' => 'John Smith', 'birthdate' => '11/15/1950'); 
$this->template->write_view('content', 'user/profile', $data, TRUE); 
在查看文件时,有点让人困惑,比如 例如,我如何访问$data数组 它必须是由第一个参数定义的$content。一个地区,或由 $name和$birthdate。。。因为上面说有$content将显示 数据阵列?这有点令人困惑。希望你能启发我

基本上这就是我的问题。

在Template.php库中,我们可以看到函数write\u视图。现在,关注$data=NULL。现在在APPPATH上找到一个包含现有数据的文件。'views/'.$suggestion.'.php',因此我认为$args[0]应该是一个加载并破坏它的文件,而不是在$data上加载视图模板

另一种方式,$data应该作为数组,它将响应CI的Codeigniter库标准视图上的视图模板数据:$this->CI->load->View

在模板文件“/user/profile.php”中,使用以下示例:

HTML/PHP模板文件profile.PHP:

!!!!!
简单地说,他无法访问私有访问变量&u ci\u cached\u vars,该变量存储的数据如$name。相关主题:

那么基本上它不在$content区域?我真的不明白你的意思,但根据他的网站上的用户指南,它说/*模板加载带有传入的$data数组的views/user/profile.php视图,并将结果写入$content区域,覆盖该区域中以前的任何内容*/是,但在添加模板之前,应该在$template数组中定义一个区域。我已经完成了必要的阵列配置,但是,当我尝试使用views/template.php上的$content在$data数组上显示数据时,我感到困惑,它说它不存在,但当我尝试使用$name和$birthdate访问它时,它的finePut在视图模板var_dump$GLOBALS中。我认为缺少变量,或者您没有很好地指向数组。我需要在$GLOBALS中找到什么?
function write_view($region, $view, $data = NULL, $overwrite = FALSE)
   {
      $args = func_get_args();

      // Get rid of non-views
      unset($args[0], $args[2], $args[3]);

      // Do we have more view suggestions?
      if (count($args) > 1)
      {
     foreach ($args as $suggestion)
     {
        if (file_exists(APPPATH .'views/'. $suggestion . EXT) or file_exists(APPPATH .'views/'. $suggestion))
        {
           // Just change the $view arg so the rest of our method works as normal
           $view = $suggestion;
           break;
        }
     }
      }

      $content = $this->CI->load->view($view, $data, TRUE);
      $this->write($region, $content, $overwrite);

   }
$data = array('name' => 'John Smith', 'birthdate' => '11/15/1950'); 
$this->template->write_view('content', 'user/profile', $data, TRUE); 
Your name: <?php echo $data["name"]; ?>
Your name: <?php echo $data["birthdate"]; ?>
$template['default']['regions'] = array(
  'header' => array(
    'content' => array('<h1>Welcome</h1>','<p>Hello World</p>'), ### <----- AS EXAMPLE
    'name' => 'Page Header',
    'wrapper' => '<div>',
    'attributes' => array('id' => 'header', 'class' => 'clearfix')
  )
);
$template['default']['regions'] = array(
  'header',
  'content',
  'footer',
);