Codeigniter Administrative Area Controller

Asked

Viewed 614 times

1

I am developing a website with administrative area. I started it with the new version of Codeigniter 3.1.5. In the main pages would be body of the site, already in the news pages the url would be as follows: www.exemplo.com/noticia/visualizar/id with the controller news and display function responding to url.

Already on the administrative page the link would be www.exemplo.com/admin with the controller admin bringing the main page of the administrative area. From this URL controllers add news, photos, etc. Must respond to url for example: www.exemplo.com/admin/noticia/adicionar with the controller noticia after the admin in the url. I thought I’d put two Framework in the hosting one in the root folder and the other in admin. But I don’t think I’m the best. I read about extends class, but I don’t know if I’m on the right track.

1 answer

2


Do the following, inside the folder application/controllers (using the concept of controls in sub-directories via documentation) create a folder named after admin, example application/controllers/admin, and now all the controllers that are part of the administrative area make the file in there, example:

inserir a descrição da imagem aqui

and to call this page in the browser do so:

inserir a descrição da imagem aqui

this already guarantees even the name of the route. Other files can continue in the same way, ie in the same folder application/controllers.

This process is also good for organizing your code by separating what is administrative and what is for everyone to access.

If you want to create a default route for this folder goes in application/config/routes.php and add at the end of the file like this:

$route['admin'] = 'admin/home/index';

when falling in the route admin will access by default the controller Home and the method index

References:

  • Friend also tried this and it did not work, since I used this method in codeigniter 2.X, so I searched the net how to do in 3.x and found what I commented on the question. But I’ll try again, maybe I’ve been hit by something.

  • Just to inform @Williancoqueiro this process was carried out in version 3 maybe missing something! got it? it also works in 2

  • And so. From your references that you gave me of the documentation I saw that really has to work. Amazing as I read the documentation before and did not find. kkk I thought I had detached from the previous version or was bug fix.

  • Well, it doesn’t work. I have controllers/home.php, controllers/noticia.php, controllers/admin.php, controllers/admin/noticia.php, controllers/admin/foto.php and not for sure.

  • not sure what? What happens? @Williancok if you’re doing it wrong I think (an admin.php thing and then an admin folder can cause problems)

  • You have to evaluate your routes... for example if you can’t get on the route /admin/foto

  • Now I’m on the mobile. More I can’t access direct. Really is the admin.php. Passed beaten. Tomorrow Vo try.

  • It worked. It was the admin folder conflicting with the admin.php file inside the root folder of controllers

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.