Well... I'm out of ideas on what to write about. Do you have any ideas? Please, write me in any comment section you find, and I will do my best to tell you about that particular subject

Step 8 – Putting it all together. How do visitors access our pages

Created at: September 9, 2015; Last update: November 27, 2015

(created at: September 9, 2015; last update: November 27, 2015)
Well… This seems to be the last step in developing our multi-language site. We did all the things we needed to do to administer the pages, the posts and the categories. But what now? How do the visitors see our pages.

Because we already had the ability to add slugs to our contents, now we should allow the visitors to have a SEO friendly url when visiting a page. Let’s say that we saved a page that has “this-is-a-great-page-about-something” as slug. People should access the page by typing:

As you can see, we’ve first made sure that, whatever the language, when a link is accessed and points to an existing controller, the same controller is accessed. What I mean by this is the fact that if someone for example access the “www.yourwebsite.com/bienvenu/list“, the content will be served from the “welcome/list” controller/method. The same could be said about any other language that is not the default language (in this particular case, english). So you only have to append to the $controllers_methods array another key in the language you want to add.

Now, after we’ve made sure that all the controllers and methods are verified, if the address doesn’t point to any of these, we redirect the visitors to a “default” controller and method: “findcontent/index“. Once we did this, it’s time to create it. So what would this controller/method do? It will take the slug from our url and simply look if there is such a slug in our database.

As you can see, we first take a look at our url to see if there is a language slug in it, and only if that part of url doesn’t exist in our url we know that that particular part is part of our slug that we need to find.

After that we look if the slug exists in our database. If it does, then we make sure that that slug is not redirected to another slug. If it is redirected, it is best to do a redirect to the new slug with a “moved permanently” code (301).

If the slug is not a redirect we look for the content, but we make sure that the content is in the language already set by the visitor. Once we’ve found out what type of content it is, we can simply call the according page template (assuming we have a template for pages, a template for posts, and a template for categories).

Disclaimer: I sure hope you can now make a website by yourselves starting from this series. If you still feel left in the dark, or something doesn’t work, there may be the possibility that I have forgot to mention something in any of my episodes. Go figure, this series was actually a work in progress. That means that if somewhere in my episodes I found that something from the previous episodes didn’t work, I returned and made some changes (I sure hope I’ve changed the tutorials accordingly). Anyways, if you liked the philosophy behind my tutorials, and you want to simply use what we’ve created together, you can at any time download the project from my Github Repository: https://github.com/avenirer/CodeIgniter-multilanguage-site

Do not feel discouraged if you want to put some questions. I am open to any doubts you may have, and I will answer them the best I can (as long as it’s not a particular problem, like developing a particular site).

Well… as you should clearly see from this tutorial, the Findcontent controller is serving the views depending on the urls it receives. It looks for those urls inside the slugs table, after it finds out to which content type the url is referring, it simply serves the appropriate view, be it page, post, or category. You can, of course, create different methods depending on the content type inside this controller, and let the controller call the appropriate methods which will serve the content the way you want it too. The way I’ve imagined it is a SEO-friendly way, with no intermediate segments to be repeated, like in your example (../page/1/…).

Hello! Thank you for a great tutorial! But I’ve little bit confused with categories. I’ve created a “news” category and add some posts with this category, how I can show all my posts to users on page e.g. “/news/”? Because view of category consist of “title” and “content’.

Hello all of what you teach about CI looks great and done with involvement and passion.

I’m wondering about a new tutorial that could make sense, since it imply to think about implementing also a knowledge base, notifications for users, replies through email etc.

A ticket system.

Notifications are intended as , users and operators will write tickets (messages) and the counterpart will receive email notifications and e.g. users will have the chance/option to reply the ticket messages WITHOUT logging into the ticket system and instead they will reply the notification email.

Tickets will be assigned to operators and to departments etc etc.

This system would involve a lot of challenges and could be become an interesting advanced Codeigniter 3 tutorial

What do you think about it?

Thank you for your tutorials !
though, I agree with your recent post http://avenir.ro/why-develop-a-web-app-with-codeigniter-in-2016/ since I’m new to this argument and I’ve read about various frameworks and CI 3 looks a great and effective synthesis, fast to get ready to develop and not dispersive able to drive important projects keeping them fast and light. Yes it requires you to tackle with php language… why not???? That is the part that everyone should appreciate. you’ll know what is going on…
If you allow, about teaching, in my learning curve, I have found fundamental this teach about OOP (also for the simplicity with which it has been written) http://www.killerphp.com/tutorials/object-oriented-php/ , understanding OOP is basic for people that begins from scratch.

But what if slug was not inserted then we wont be able to access that content (category-post-page) at all ?

If so then i have another question is how can i make a condition in Findcontent.php or routes.php to check if for example a category slug was empty then it redirect be to default url like http://www.domain.com/categroy/30

If you’ve followed the tutorial you should see that the slug is automatically created by the cms if no slug is provided (it is created from the title of the content). There is no chance for the cms to create the same slug for two or more contents because it first verifies if that slug exists and if it does it appends a number at the end of the slug.

Thank you so much .. ok that’s my mistake i didn’t totally follow the tutorial but now i see the problem is when i was adding a page title in Arabic (my language) it wasn’t saved but when i tried again in english it was saved just fine.In a CMS like WordPress i used to see arabic slugs get saved encoded something like this %d8%ba%d9%8a%d8%b1-%d9%85%d8%b5%d9%86%d9%81

HI, very good tutorial, but i have one question, i created secondary menu in the admin dashboard but i don’t understand how to add it to the page to show? for example if i want to have 2 menus (top-menu and side-menu). Thank you for your answer 🙂

As you may have seen in the public controller the $top_menu that is called inside the header view is created inside the render method: $this->data[‘top_menu’] = $this->menus_creator->get_menu(‘top-menu’,$this->current_lang,’bootstrap_menu’);

So if, for example you want to create a $side_menu variable you simply duplicate that line and change top-menu to whatever name you made for that menu:
$this->data[‘side_menu’] = $this->menus_creator->get_menu(‘side-menu’,$this->current_lang,’bootstrap_menu’);