A slug is a part of the URL when you are accessing a resource. in this tutorial we are creating a slug by using the helper function.
Create a controller
File Name : Slug_controller.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Slug_controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('Auth_model');
$this->load->helper('common');
$this->load->helper('text');
$this->load->helper('url');
}
public function index()
{
$this->load->view('slug-view');
}
public function save_slug()
{
$title = $this->input->post('title');
//echo $slug = slug($title); // call slug helper function
echo $slug = slugify($title); // call slugify helper function
// Check if the function does not exists
if ( ! function_exists('slugify'))
{
// Slugify a string
function slugify($string)
{
// Get an instance of $this
$CI =& get_instance();