Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/318.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
Codeigniter Pyrocms问题:如何使用标签显示页面中表格中的单个记录_Codeigniter_Html Table_Record_Pyrocms - Fatal编程技术网

Codeigniter Pyrocms问题:如何使用标签显示页面中表格中的单个记录

Codeigniter Pyrocms问题:如何使用标签显示页面中表格中的单个记录,codeigniter,html-table,record,pyrocms,Codeigniter,Html Table,Record,Pyrocms,我已经创建了一个插件,它从db表中带来了一条记录。现在我想在页面中显示记录。我正在尝试使用标签,但无法使其工作。我该怎么做? 详情如下: 插件 class Plugin_News extends Plugin { function getNewsDetails() { $this->load->model('news/news_m'); $result = $this->news_m->getNews(); ret

我已经创建了一个插件,它从db表中带来了一条记录。现在我想在页面中显示记录。我正在尝试使用标签,但无法使其工作。我该怎么做?
详情如下:

插件

class Plugin_News extends Plugin  
{  
   function getNewsDetails()  
   {  
    $this->load->model('news/news_m');
    $result =   $this->news_m->getNews();

    return $this->attribute('result',$result);
   }       
} 
模型

下面是我如何称呼它的

{{ News:getNews }}  
<li><a href  = "http://localhost/lc/index.php/newsdetail?id={{ id }}">{{ news_title }}</a></li>
{{ /News:getNews }} 
{{News:getNews}
  • {{/News:getNews}
    并在newsdetails页面中显示单个记录

    <tbody>
        <tr>
            <td>{{ News:getNewsDetails news_title}}  </td>
        </tr>
        <tr>
            <td>{{ News:getNewsDetails description }}</td>
        </tr>
    </tbody>
    
    
    {{News:getNewsDetails新闻标题}
    {{News:getNewsDetails description}
    

    它不起作用,我无法理解正确的syntex,在文档中也没有发现任何清晰的东西。经过一点研究,我找到了这个替代方案。
    在模型中,返回此

    return  $query->result();
    
    但查询应限制为1

    SELECT id,news_title , news_description ,FROM default_news $where limit 1
    
    在页面中,只需创建一个循环来显示内容

    {{ News:getNewsDetails}} 
    <tbody>
        <tr>
            <td>{{ title }}</td>
        </tr>
        <tr>
            <td>{{ description }}</td>
        </tr>
    </tbody>
    {{ /News:getNewsDetails}} 
    
    {{News:getNewsDetails}
    {{title}}
    {{description}}
    {{/News:getNewsDetails}
    

    我知道这并不完美,但这符合我的要求。

    经过一番研究,我找到了这个替代方案。
    在模型中,返回此

    return  $query->result();
    
    但查询应限制为1

    SELECT id,news_title , news_description ,FROM default_news $where limit 1
    
    在页面中,只需创建一个循环来显示内容

    {{ News:getNewsDetails}} 
    <tbody>
        <tr>
            <td>{{ title }}</td>
        </tr>
        <tr>
            <td>{{ description }}</td>
        </tr>
    </tbody>
    {{ /News:getNewsDetails}} 
    
    {{News:getNewsDetails}
    {{title}}
    {{description}}
    {{/News:getNewsDetails}
    

    我知道这并不完美,但这符合我的要求。

    在您的车型中,这是一种更快的方式

    public function getNews()
    {       
        $id =   isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
        if($id > 0 )
        {
            $where  =   "id = $id"; 
        }else{
            $where  =   "";
        }
        return $this->db->select('id, news_title , news_description')
               ->from('news')->where($where)->get()->row();
    }
    
    您可以在模型中使用这条线

    public function getNews()
    {       
        $id =   isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
        if($id > 0 )
        {
            $where  =   "id = $id"; 
        }else{
            $where  =   "";
        }
        return $this->db->select('id, news_title , news_description')
               ->from('news')->where($where)->get()->row();
    }
    

    只是在你的模型中有一个更快的方法

    public function getNews()
    {       
        $id =   isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
        if($id > 0 )
        {
            $where  =   "id = $id"; 
        }else{
            $where  =   "";
        }
        return $this->db->select('id, news_title , news_description')
               ->from('news')->where($where)->get()->row();
    }
    
    您可以在模型中使用这条线

    public function getNews()
    {       
        $id =   isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
        if($id > 0 )
        {
            $where  =   "id = $id"; 
        }else{
            $where  =   "";
        }
        return $this->db->select('id, news_title , news_description')
               ->from('news')->where($where)->get()->row();
    }
    

    这是正确的方法!如果您有更多truoble,请参阅文档:这是正确的方法!如果您有更多truoble,请参阅文档:好的,谢谢,但是我已经尝试返回一行,但是在页面中我不知道如何使用它。好的,谢谢,但是我已经尝试返回一行,但是在页面中我不知道如何使用它