I can't find a way to hide the name of the controller and its function, in the url of my website.
I have several controladores
, one of them is blog
, which is the one controlador por defecto
established in the routes.php
.
$route['default_controller'] = 'blog';
I have been trying several things, among them, setting the following code in the routes.php
.
$route['entradas'] = 'blog/entradas';
But I can't get it to work and it's something that drives me crazy, since I'm currently learning codeigniter, if someone can enlighten me I'd appreciate it
You can define a custom route in config/routes.php , for example:
In other words more explained:
There is a file where we can generate all kinds of rules to achieve a routing of URIs different from the default. That file can be found in the configuration files directory:
There we can define an array called $route where we will place all the routing rules that we want to create specifically in our CodeIgniter web application .
If we open the mentioned file we can see that there are already two routing values defined in the $route array .
Those two routing values are proprietary to CodeIgniter and are reserved for any other use. We can change the default routing values for those variables, but we can't create routes for our application using them. Furthermore, these two default routes must appear before any other routes that we define later in the routes.php file .
So, to create our own rules, it would simply be a question of assigning new values to the $route associative array and for this we have to follow the following syntax:
$route['from_where_are you coming'] = 'where_are you going';
As you can see, in the routes we have two parts:
At the index of the associative array, ' where you_come_from ', we put a pattern that must match for routing to occur. In the value assigned to that array index, ' to_where_go ', we put the path to which we are sending the CodeIgniter execution stream . Now let's look at an actual routing example:
More examples here
In your routes file you can put the following
With this, what you do is that with whatever name it is and the parameters passed by ´/´ they will be formatted in the function and the browser will be transparently redirected to the ´blog´ controller (to the ´entrance´ method) with the ´id parameter ´, you can put a prefix so that it does not affect you with the other pages, for example