dataflow1117@gmail.com
FacebookTwitter

en English
af Afrikaanssq Albanianam Amharicar Arabichy Armenianaz Azerbaijanieu Basquebe Belarusianbn Bengalibs Bosnianbg Bulgarianca Catalanceb Cebuanony Chichewazh-CN Chinese (Simplified)zh-TW Chinese (Traditional)co Corsicanhr Croatiancs Czechda Danishnl Dutchen Englisheo Esperantoet Estoniantl Filipinofi Finnishfr Frenchfy Frisiangl Galicianka Georgiande Germanel Greekgu Gujaratiht Haitian Creoleha Hausahaw Hawaiianiw Hebrewhi Hindihmn Hmonghu Hungarianis Icelandicig Igboid Indonesianga Irishit Italianja Japanesejw Javanesekn Kannadakk Kazakhkm Khmerko Koreanku Kurdish (Kurmanji)ky Kyrgyzlo Laola Latinlv Latvianlt Lithuanianlb Luxembourgishmk Macedonianmg Malagasyms Malayml Malayalammt Maltesemi Maorimr Marathimn Mongolianmy Myanmar (Burmese)ne Nepalino Norwegianps Pashtofa Persianpl Polishpt Portuguesepa Punjabiro Romanianru Russiansm Samoangd Scottish Gaelicsr Serbianst Sesothosn Shonasd Sindhisi Sinhalask Slovaksl Slovenianso Somalies Spanishsu Sudanesesw Swahilisv Swedishtg Tajikta Tamilte Teluguth Thaitr Turkishuk Ukrainianur Urduuz Uzbekvi Vietnamesecy Welshxh Xhosayi Yiddishyo Yorubazu Zulu

DataInFlow
DataInFlow
A Market place of programming
  • Home
  • Tutorial
    • HTML Tutorial
    • PHP TUTORIAL
  • Article
    • Technology
    • Entertainment and News
    • Game
    • Recipes
  • Queries
  • Programming
    • HTML
    • CSS
    • jQuery
    • JavaScript
    • WordPress
    • PHP
    • Codeigniter
    • Laravel
    • Ionic
    • Angular JS
    • Node JS
    • Vue JS
    • Android
    • ASP .NET
  • Sports
    • Cricket
    • Football
    • Football Live Score
  • Web Tools
  • Home
  • Tutorial
    • HTML Tutorial
    • PHP TUTORIAL
  • Programming
  • Queries
  • Sports
    • Cricket
    • Football
    • Football Live Score
  • Article
    • Entertainment and News
    • Technology
    • Recipes
    • Game
  • Web Tools
  • About Us
  • Contact

Generate URL slug in Codeigniter

November 16, 2018By Samir Jana

Hi, friends. I am back with a new and interesting tutorial for you.This tutorial help you to generate SEO friendly URL slug. If you are working with PHP or Codeigniter then this tutorial will so much helpful for you.. I will tell you first that this tutorial for those people who develop their website using PHP.

What is URL slug:

For a blog site url slug is the most improtant to search a post. Because a url slug is detected the address of a particular post or a page on your website. A SEO friendly URL slug is the part of a URL that is collection from post title or page title. For example: “php-database-connection”.

Generate SEO friendly URL slug from POST title:

If you want to generate dynamically and SEO friendly URL slug then follow my steps, you can create a good SEO friendly URL slug from your post title.

Create MySQL table:

Follow the below instruction and create a table with these field.

1
2
3
4
5
6
7
8
9
10
11
CREATE TABLE `blog` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`post_title` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`url_slug` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`post_category_id` int(11) COLLATE utf8_unicode_ci NOT NULL,
`post_image` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`post_description` text(1000) COLLATE utf8_unicode_ci NOT NULL,
`created_date` datetime NOT NULL,
`update_date` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Insert POST (Controller)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
public function insert_blog(){
$url_slug=$this->generate_url_slug($this->input->post('post_title'),'blog');
$config['upload_path'] = './assets/images/post_image';
$config['allowed_types'] = '*';
$this->load->library('upload', $config);
$this->upload->do_upload('post_image');
$up_file_name = $this->upload->data();
$post_image=$up_file_name['file_name'];
$created_date=date('Y-m-d h:i:s');
$update_date=date('Y-m-d h:i:s');
$data=array('post_title'=>$this->input->post('post_title'),'url_slug'=>$url_slug,'post_category'=>$this->input->post('post_category'),'post_image'=>$post_image,'post_description'=>$this->input->post('post_description'),'created_date'=>$created_date,'update_date'=>$update_date);
$this->PostModel->InsertBlog($data);
}
?>

 

Generate URL slug (Controller)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
function generate_url_slug($string,$table,$field='url_slug',$key=NULL,$value=NULL){
    $t =& get_instance();
    $slug = url_title($string);
    $slug = strtolower($slug);
    $i = 0;
    $params = array ();
    $params[$field] = $slug;
    if($key)$params["$key !="] = $value;
    while ($t->db->where($params)->get($table)->num_rows())
    {  
        if (!preg_match ('/-{1}[0-9]+$/', $slug ))
            $slug .= '-' . ++$i;
        else
            $slug = preg_replace ('/[0-9]+$/', ++$i, $slug );
        
        $params [$field] = $slug;
    }  
    return $slug;  
}
?>

Insert POST (Model)

1
2
3
4
5
6
7
8
9
10
11
12
<?php
function InsertBlog($data){
$ins_qry=$this->db->insert('blog',$data);
if($ins_qry){
$this->session->set_flashdata("success","Success! Blog create successful!");
return redirect('page url');
}else{
$this->session->set_flashdata("error","Error! Blog create faild!");
return redirect('page url');
}
}
?>

Post Views: 1,543
Share this post
FacebookTwitterLinkedIn
About the author

Samir Jana

My work is usually in PHP Framework, earlier I had worked on Codeigniter framework, Laravel framework, WordPress development, PHP API, and Ionic app. Now I'm learning NodeJS. I love learning new things and update myself with the latest technologies.

Related posts
Export data to excel in Codeigniter
July 8, 2019
Load more results functionality with jQuery , Ajax and PHP
January 14, 2019
Facebook login with JavaScript SDK
September 1, 2018
Facebook login in Codeigniter and MySQL
June 28, 2018
Live search like google in Codeigniter, jQuery
May 18, 2018
facebook twitter share
Add facebook & twitter share link in your website
May 6, 2018
3 Comments
  1. Reply
    July 9, 2019 at 12:09 am
    Korey Klem

    If you wish for to obtain a good deal from this piece of writing then you have to apply such methods to your won web site.

  2. Reply
    October 4, 2019 at 3:30 am
    rardHooma

    Hello. And Bye.

    • Reply
      October 9, 2019 at 11:50 am
      Yesuus

      Hi, Thanks for comment here.

Leave Comment

Cancel reply

Your email address will not be published. Required fields are marked *

clear formSubmit

Subscribe to our Newsletter
Search anything
Questions
What is the best editor/IDE for php? 5 Answers | 0 Votes
how to search similar names given by 2 or 3 words ? 11 Answers | 0 Votes
How is the answer coming 1 Answer | 0 Votes
How to set a session variable in laravel 5.2 3 Answers | 0 Votes
How to change input placeholder name using jquery? 2 Answers | 0 Votes
Recent Programming Article
  • Menu hide from sidebar in ionic 3
    May 29, 2019
  • Generate bootstrap modal in angular 6
    May 28, 2019
  • Load more results functionality with jQuery , Ajax and PHP
    January 14, 2019
  • Facebook login with JavaScript SDK
    September 1, 2018
  • Facebook login in Codeigniter and MySQL
    June 28, 2018
Hire us

Hi
Do you want to make web application with php and php framework(CI, Laravel)? Want to make android application with hybrid framework ? Then contact with us. We provide support for developing website and web application at very affordable price.
E-Mail us at: dataflow1117@gmail.com

Recent Technlogy News
  • Astrology Software: Perfect Tool for Astrologers to Earn Money Online
    November 7, 2019
  • Actionable Steps to Secure Workplace for Dummies
    October 14, 2019
  • The Best Spy Glasses in 2019 You Can Buy now
    September 5, 2019
© Copyright 2017-2018 DataInFlow

About Us    Privacy policy    Contact us

Login

Lost your password?

Reset Password

Log in

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.