Welcome Guest, Not a member yet? Register   Sign In
Building frontend + backend : best practices ?
#1

[eluser]Isuka[/eluser]
Hi guys,

I'm thinking about my development process and I want to know how you guys doing things when you build a website with a backend.

Since I build website with CI, I make 2 separate applications : one for the frontend and one for the backend.

My structure look like this :
Code:
.htaccess
admin
  .htaccess
  .htpasswd
  index.php
applications
  - backend
    - config
    - controllers
    - helpers
    - models
    - modules
    - views
    - ...
  - frontend
    - config
    - controllers
    - helpers
    - models
    - modules
    - views
    - ...
index.php
skins
  - backend
    - css
    - img
    - js
  - frontend
    - css
    - img
    - js
system
I like this structure because the frontend and the backend are dissociated.
I can quickly protect the backend with an .htaccess in the admin folder for exemple.

But the boring things is that I need to duplicate some frontend and backend common libraries and helpers or duplicate models for each app when models are almost the same.

Of course I could make an unique application and make an admin controller in it but I don't like this idea because I think a backend is an application on its own.
I need also to duplicate my config files when there are the same. Kind of things annoying.

(Is this possible to have a common libraries or helpers folder or config file accessible from both frontend and backend app ?)

I'm curious how you guys handles that.
#2

[eluser]SitesByJoe[/eluser]
I'm not quite sure why you separate everything into 2 completely separate applications - I've never done that myself.

Is it for ajax stuff? I've never seen that its necessary.
#3

[eluser]Bramme[/eluser]
What I do is create a subfolder in my controller folder called "admin". You can still use .htaccess to protect it, but libraries and models are shared!
#4

[eluser]Isuka[/eluser]
The first time I used a framework to build website, I tried Symfony and that's the way this framework works : you build an app for the frontend and another for the backend. So naturally I applied the same system with CI. It was logical to me that a frontend and a backend are 2 differents applications.

But it's seems that I'm the only one here who build a website this way Tongue
Maybe I should try to simply make a admin folder in my controller.

@Bramme : Where do you put your .htacces and .htpasswd the ? Simply in the admin folder of your controllers folder ?
#5

[eluser]Bramme[/eluser]
[quote author="Isuka" date="1224283314"]It was logical to me that a frontend and a backend are 2 differents applications.

@Bramme : Where do you put your .htacces and .htpasswd the ? Simply in the admin folder of your controllers folder ?[/quote]I must say that looks unlogical to me... In the end, the backend is a supporting feature of your frontend, the two are meant to be used together... Word and Excel are two different applications...

I don't password protect the folder with .htaccess, so I wouldn't know. I guess you would put it in the application/controllers/admin folder.
#6

[eluser]Isuka[/eluser]
[quote author="Bramme" date="1224283728"]In the end, the backend is a supporting feature of your frontend, the two are meant to be used together...[/quote]
You're right, the backend is a feature of the frontend.

But, for me, a backend has it's own views, models, assets (css, js and images), it's own config files, libraries and helpers that they don't need to be in the frontend.

In my opinion, a frontend model for exemple don't need to have the methods specific to a backend model, like a save() or update() method.
#7

[eluser]JoostV[/eluser]
I'm with Bramme on this one. I like front end and back end to share models and libraries. Some methods you will only use in back end, such as delete(). But many methods will be shared. Sharing models and libraries helps you to write less redundant or repetitive code.

Of course, it is still possible to create a backend_config.php and a frontend_config.php, and even seprate helper files if you need to.

Furthermore I would remove /system and /applications from you webroot, for security. This would leave you with:

-applications [folder]
-system [folder]
-webroot [folder]
-index.php
-.htaccess
-robots.txt
-skins [folder]
#8

[eluser]Isuka[/eluser]
I'm going to try the way you guys doing. Clearly having models and libraries shared between frontend and backend is really advantageous.

What was great with my method I could quickly and easily make the backend app private with an .htaccess and .htpasswd in the admin folder (for small site it was sufficient for my clients). I'm curious how you make that with the admin in the controllers directory. With a complete authentification module ?
#9

[eluser]manilodisan[/eluser]
Why not start with an already built backend and focus on the frontend? Tongue It has everything you need to start with an advanced user management and also expands in a modular way. It was developed in such away that building an advanced module sometimes takes less than a day.
#10

[eluser]JoostV[/eluser]
@isuka: yep, an authentication module is the way to go. I use my own, but from what I heard Freak Auth seems to be pretty good to use out of the box.




Theme © iAndrew 2016 - Forum software by © MyBB