简体   繁体   English

在Codeigniter PHP中将博客页面标题显示为URL

[英]Displaying the blog pagetitle as a url in codeigniter php

I am having a blog page where the blogs are inserted from admin panel and blog title will be inserted into new column as separated by " - " if there are spaces between the page titles.For example if the page title is " welcome to something " then in the database it is will be inserted into two columns. 我有一个博客页面,其中从管理面板插入博客,如果页面标题之间有空格,则博客标题将插入新列,并以“-”分隔。例如,如果页面标题为“ welcome to something”然后在数据库中将其插入两列。 In once column it will be inserted as same and in other column it will be inserted as welcome-to-something. 在同一列中,它将以相同的方式插入,在其他列中,将以“欢迎插入”的方式插入。

when clicking on readmore button i need to display in url as (www.example.com/blob/article/welcome-to-something) in this format i need to display the url. 当单击readmore按钮时,我需要以这种格式在网址中显示为(www.example.com/blob/article/welcome-to-something),我需要显示该网址。

Here is the code: 这是代码:

Controller: 控制器:

public function index()
    {
        $this->load->model('blogs_model');          
        $data["records2"] = $this->blogs_model->get_all_blogs($config["per_page"], $page);
        $data['mainpage'] = "blog";
        $this->load->view('templates/template',$data);
    }

    public function article()
    {
      $this->load->model('blogs_model');
      $data['records2']= $this->blogs_model->getblogsdata($this->uri->segment(3));                
      $data['mainpage']='blogs';
      $this->load->view('templates/templatess',$data);

    }

Model: 模型:

function get_all_blogs()
{
    $this->db->select('B.*');
    $this->db->from('blogs AS B');
    $this->db->where(array('B.status'=>1));
    $this->db->order_by("position", "asc");
    $q = $this->db->get();
    if($q->num_rows()>0)
    {
        return $q->result();
    }
    else 
    {
        return false;
    }
}

function getblogsdata($id)
{
    $this->db->select('blogs.*');       
    $this->db->from('blogs');
    $this->db->where(array('blogs.blog_id'=>$id));
    $q=$this->db->get();        
    if($q->num_rows()>0)
      {
    return $q->result();
        }
    else
    {
    return false;
    }
}

View: 视图:

  <div class="col-md-9 blogs"> 
            <?php if(isset($records2) && is_array($records2)):?>
            <?php foreach ($records2 as $r):?>          
                <div class="blog1">
                    <img src="<?php echo base_url();?>admin/images/blogimages/thumbs/<?php echo $r->image_path;?>" class="testimonials1"/>
                    <h3 class="heading1"><?php echo $r->blog_title;?></h3>
                    <div class="blogtext1 read">                        
                        <?php echo $r->description;?>
                    </div>
                    <a href="<?php echo base_url()?>blog/article/<?php echo $r ->blog_id ;?>" class="read_more7" target="_blank" >Read More</a>
                </div>

            <?php endforeach ;endif;?>
            <div class="pagination"><?php echo $links; ?></div> 
            </div>

blogs table 博客表

blog_id | blog_id | blog_title | blog_title | blogtitle 1 welcome to something welcome-to-something Blogtitle 1欢迎来到欢迎事物

Model: 模型:

function getblogsdata($id,$slug)
{
    $this->db->select('blogs.*');       
    $this->db->from('blogs');
    $this->db->where(array('blogs.blogtitle'=>$id));
    $this->db->where(array('blogs.blogtitle' => $slug));
    $this->db->order_by("ne_views", "asc");         
    $q=$this->db->get();

    if($q->num_rows()>0)
      {
    return $q->result();
        }
    else
    {
    return false;
    }
}

View: 视图:

<a href="<?php echo base_url()?>blog/article/<?php echo $r->blogtitle;?>" class="read_more7" target="_blank" >Read More</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM