Step 6 – Creating categories for a multilanguage site in CodeIgniter

(created at: February 10, 2015; last update: April 13, 2015)
Well… This tutorial is in two versions. Let me explain why…

The first time I created the tutorial, back in 10 february 2015, I was still in some testing regarding a multilanguage CMS, but now, in april 2015, all seems a bit clearer. So, after I’ve created an admin area for pages, I returned to this tutorial about categories and I found myself saying “What the fuck was I thinking??? Packs??? What is thaaat??? A name column in categories table??? WHYYYYYY???”. If you still want to see that old tutorial, you can, as I’ve left it at the bottom of this new version.

And when I am saying “new version” I am actually saying that we should simply do the same as we did in the previous tutorial about creating, listing and editing pages. The only difference would be the name of the tables and replacing “page” or “pages” in the code with “category” and “categories”. Simple, no?

The tables

The models

The Controller

The views

And that’s it. BUT… Did you notice something about the Pages controller and the Categories controller? Is there something fishy in there? Please comment below if you notice what I am talking about. If you don’t know what I am talking about, I will tell you in the next episode.

Here you have an ARCHIVE WITH THE APPLICATION we’ve created so far. Take care as this archive is not containing a system directory. You should download a fresh copy of CodeIgniter 3, put all the files from the archive inside your fresh framework, set the database configuration and then import the ci_app.sql into your database.

Now… the old tutorial follows:

Once we’ve made our multilanguage site we must think about populating it with content. So let’s start by creating the categories for our posts.

How do we organize our tables

First thing to think about is the layout (schema) of our database. We already have a table named languages. So let’s think how we can set the tables so that they will allow for same content to be available in several languages. We will try to create tables that will be very comprehensive.

The packs table

In the pack table will have e some general data that is the same for all languages:

– an id column
– a type column (example of types: menu_items, categories, posts, pages)
– a parent_id column
order column (who knows, maybe we need to order the items)
– a created_at column
– an updated_at column
– a created_by column
– an updated_by column

Ok. Let’s create it:

We should also add an index on name column.


The categories table

Now let’s create the categories table. For this we will need the following columns:

– an id column
– a pack_id column
– a language_id column
– a name column
– a description column
– a slug column

And that’s about it…

So the MySQL will look like this:

Now, let’s do an index on slug column.

OK. Database ready for categories.

Now let’s look at our files








Well… As you can see, creating a multilanguage site is not that easy as it may seem…

0 thoughts on “Step 6 – Creating categories for a multilanguage site in CodeIgniter

  • Noticed you merged the category_translation and the page_translation. Why were they separate in the first place.I was wondering what the categories were. Great tutorial. I was searching on how to use Ion_auth. This opened my eyes to multi_language applications which is great. Nice one

    • Are you referring to one of my Github repositories ( If you are, then congratulations for looking into it 🙂 What I thought in the first place when creating the multilanguage site was to have different tables for different content types, thinking that… well… they are different. But a week ago I thought: “Wait a minute… They are not that different… So why not create a ‘contents’ table and a ‘content_translations’ table?”.

      PS: If you want to try the site on Github, you can use “administrator” as username and “password” as password.

        • This is a tutorial, not an application for you to test… You are doing the testing by creating the categories, editing them, deleting them and listing them.

      • Hi Avenir ,

        Why this site wont work when i try to load from localhost ? It shows to me a lot of errors and when i try to login it just refreshes the page , and when i check in database there is no username and password registered as you have mentioned . I downloaded the code from your git repository but it doesn’t work for me . Can you help me ?

        Thanks !

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

No spam? * Time limit is exhausted. Please reload CAPTCHA.