Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.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 href视图控件中的问题_Php_Mysql_Codeigniter - Fatal编程技术网

Php href视图控件中的问题

Php href视图控件中的问题,php,mysql,codeigniter,Php,Mysql,Codeigniter,我有一个带有特定链接的页面,该链接将调用视图。该视图在控制器中的响应功能执行后显示 html页面包含以下行 <a href="xxxxxxx">Click to view</a> 控制器包含 public function get_comments() { if(!file_exists('application/views/blog/list_comment_view.php')) { show_40

我有一个带有特定链接的页面,该链接将调用视图。该视图在控制器中的响应功能执行后显示 html页面包含以下行

<a href="xxxxxxx">Click to view</a>

控制器包含

public function get_comments()
    {
        if(!file_exists('application/views/blog/list_comment_view.php'))
        {
            show_404();
        }
        else
        {
            $row_nums=$this->blog->get_row_nums();
            $config['base_url']=base_url().'index.php/blog/list_comment_view';
            $config['total_rows']=$row_nums;            
            $config['per_page']=5;
            $config['num_links']=2;
            $config['full_tag_open']='<p>';
            $config['full_tag_close']='<p>';
            $config['first_link']='First';
            $config['last_link']='Last';
            $this->pagination->initialize($config);
            $data['comments']=$this->blog->get_comments($config['per_page'],$this->uri->segment(3));
            $this->load->library('table');
            $this->table->set_heading('No','Title','Created','Modified','Action');
            $this->load->view('blog/list_comment_view', $data);
        }
    }
public函数get_comments()
{
如果(!file_存在('application/views/blog/list_comment\u view.php'))
{
show_404();
}
其他的
{
$row_nums=$this->blog->get_row_nums();
$config['base_url']=base_url().'index.php/blog/list_comment_view';
$config['total_rows']=$row_nums;
$config['per_page']=5;
$config['num_links']=2;
$config['full_tag_open']='';
$config['full_tag_close']='';
$config['first_link']='first';
$config['last_link']='last';
$this->pagination->initialize($config);
$data['comments']=$this->blog->get_comments($config['per_page'],$this->uri->segment(3));
$this->load->library('table');
$this->table->set_heading('No','Title','Created','Modified','Action');
$this->load->view('blog/list\u comment\u view',$data);
}
}
list_view.php是

<body>
<div>Welcome ,
<?php
    $array=$this->session->userdata('db_result');
    echo $array[0]['name'];
?></div>
<?php    

    $this->table->generate($comments);
    $this->pagination->create_links();
?>
</body>

欢迎
我想知道我应该用什么替换XXXXXX,因为我直接在那里放了“get_comments”,但它无法显示list_view.php。没有显示任何内容,因为list_view.php中的$comments值为零


对不起大家,它确实有效,很好。我忘了“回显”生成($comments);:-D感谢大家的阅读和关注。

如果未加载,则通过以下方式将其加载到控制器(即加载视图)中:

如果已加载(自动加载),则跳过此行

<a href="<?php echo site_url("classname/get_comments");?>">Click to view</a>


classname是包含函数get\u comments的类的名称。有关更多信息,请阅读位于

的文档,我不知道codeigniter,但如果我不得不猜测,您似乎必须在url上指定每页计数。所以
href
类似于
/index.php/blog/list\u comment\u view/10
。是否要通过单击上面提到的链接来执行函数“get\u comments()”?我想是的,我也是这样做的,因为我想我也会为自己加载视图。我很高兴你发现并解决了你的问题,但是,我能提供一些建议吗?通过在视图中包含赋值并使用$array[0]['name']等变量,您在某种程度上打破了MVC模式。数据从控制器传递到视图的方式应确保它需要一个简单的回音来显示,就是这样。事实上,如果您在php.ini中启用php_short_标记,您应该能够编写注释,此外,还应该在控制器中处理注释生成。这看起来没什么大不了的,但随着应用程序的增长,这将很重要。还有一件事,实际上与您的问题有关。为标记提供的href,请确保编写
,或确保识别HTML标记。这样,当您将网站移动到实时服务器或更改域时,您只需进行一次更改,而不需要进行x次更改(其中x是应用程序中标记的总数)
<a href="<?php echo site_url("classname/get_comments");?>">Click to view</a>