Create A Rich Text Editor Using TinyMCE In Codeigniter

Create A Rich Text Editor Using TinyMCE In Codeigniter

Many time we need a rich text editor when we use custom CMS. So today I will teach you how to create a rich text editor using TinyMCE in codeigniter.
Your final output looks like this:


So lets follow these steps:


Step 1.

Download CI and config it. like database, url and libraries.


Step 2.

Download tinymce javascript library form here tinymce download.
and create a folder name with asset in root directory of application and upload this tinymce library to init.


Step 3.

Create 3 php files.
home.php controller file under the directory(application/controller).
article_model.php model file under the directory (application/models).
home.php view file under the directory(application.views).


Step 4.

Write following code in home controller file or copy code and paste.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Home extends CI_Controller { public function __construct() { parent::__construct(); $this->load->model('articleModel');

public function index()

public function addArticle(){
$title =  $_POST['title'];
$article = htmlentities( $_POST['article']);
$this->articleModel->addArticle($title, $article);


public function loadArticle(){

/* End of file welcome.php */
/* Location: ./application/controllers/Home.php */


Step 5.

Now write the following code in article_model file or paste the following code in it.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class ArticleModel extends CI_Model { public function addArticle($title, $article){ $date = date('d/m/y'); $Addtitle = $title; $Addarticle = $article; $data = array('title'=> $Addtitle,
$this->db->insert('tinymce', $data);

public function loadArticle(){
$query =  $this->db->get('tinymce');

foreach ($query->result() as $row){
$date = date_create($row->created);
$date = date_format($date, 'l jS F Y');


<a href="#" class="btn btn-sm btn-warning">'.$date.'</a><hr/>';



Step 6.

Finally in step 5, write a view code or paste the following in home.php view file.

<!DOCTYPE html>
<html lang="en">
	<meta charset="utf-8">
	<title>Welcome to CodeIgniter</title>

	<!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="">

        <!-- Optional theme -->
        <script src=""></script>

        <!-- Latest compiled and minified JavaScript -->
        <script src=""></script>
        <script src="<?php echo base_url()  ?>asset/tinymce/js/tinymce/tinymce.min.js"></script>
        <script type="text/javascript">
            selector: "textarea",
            plugins: "link image"
    <div class="container">
        <div class="row clear_fix">
            <div class="col-md-12">
                <blockquote style="background: #333; color: #fff">
                <h3>Rich text editor in codeigniter</h3>
                <a href="">by TryCatch Classes</a>

                        #response{display: none}
                        div #fb, div #gp, div #tw{display: inline-block;}
                        #fb{width: 180px;}
                        #gp{width:  100px;}
                        #tw{width: 180px;}
					<div id="fb-root"></div>
					<script>(function(d, s, id) {
					  var js, fjs = d.getElementsByTagName(s)[0];
					  if (d.getElementById(id)) return;
					  js = d.createElement(s); = id;
					  js.src = "//;version=v2.7";
					  fjs.parentNode.insertBefore(js, fjs);
					}(document, 'script', 'facebook-jssdk'));</script>
                        <div id="tw">
                            <a href="" class="twitter-follow-button" data-show-count="false" data-size="medium">Follow @trycatchclasses</a>
                            <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);;js.src=p+'://';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
                        <div id="gp">
                            <!-- Place this tag in your head or just before your close body tag. -->
                           <script src="" async defer></script>
                           <!-- Place this tag where you want the +1 button to render. -->
                           <div class="g-plusone" data-href=""></div>
					    <div id="fb">
							<div class="fb-like" data-href="" data-layout="standard" data-action="like" data-size="small" data-show-faces="true" data-share="true"></div>
        <div class="row clear_fix">
            <div class="col-md-12">
                <form role="form" id="frmArticle" class="form" action="<?php echo base_url() ?>home/addArticle" method="POST">
                    <input type="text" name="title" class="form-control">
                    <textarea id="article" name="article" rows="8" class="form-control"></textarea>
                    <input class="btn btn-info btn-block" type="submit" value="Add new article" name="submit">
        <div class="row clear_fix">
            <div class="col-md-12 response">


        $("#frmArticle").submit(function (e){
            var data = $(this).serialize();
            var type = $(this).attr('method');
            var url = $(this).attr('action');
                type: type,
                data: data
            }).done(function (html){
    function loadArticle(){
                url:<?php echo base_url() ?>;home/loadArticle',
                type: 'GET'
            }).done(function (html){

So Finally your code is ready to use. You can easily integrate this code in your cms for better user UI experience.

Don’t forget to share your doubts in the comment box and also share this post on social media and with your friends becaus“You share, I share, let’s make the world aware”.

You may want to take a look at the following related posts:

Also for more awesome tutorials, please don’t forget to like our facebook page TryCatch Classes.

Bonus: We also give training on following topics:

                       1. Angular Training in Mumbai.

2. Bootstrap Training Course in Mumbai.

3.  Web Designing Training in Mumbai.

4. UI / UX Training.

5. IOS Training Institute in Mumbai.