Welcome Guest, Not a member yet? Register   Sign In
Sharing Resources between multiple applications
#1

[eluser]CodeIgniterNewbie[/eluser]
I am building a CI multi-app site. I have followed this organization:

Code:
/application/
    /frontend/
    /backend/
/system/
See: http://codeigniter.com/wiki/Multiple_Applications/

The problem I have now is that some libraries, models, etc. need to be shared between the applications. How do I do this?
#2

[eluser]bubbafoley[/eluser]
I would do it with just one app using multiple base controllers. No need to use multiple apps.

Phil has a good write up on how to do this here

So you set it up like this:
Code:
application/
    controllers/
        frontend/
        backend/
    core/
        MY_Controller.php
    libraries/
        Frontend_Controller.php
        Backend_Controller.php
    ...
system/

Then you can share your libraries.
#3

[eluser]CodeIgniterNewbie[/eluser]
@bubbafoley - I'm a bit confused about your suggestion. Which folders should be in application/controllers/frontend and application/controllers/backend? Do I put models/, helpers/, etc. in application/ folder so that the controllers/frontend/ and controllers/backend/ can access them?
#4

[eluser]CodeIgniterNewbie[/eluser]
[quote author="bubbafoley" date="1298617803"]

So you set it up like this:
Code:
application/
    controllers/
        frontend/
        backend/
    core/
        MY_Controller.php
    libraries/
        Frontend_Controller.php
        Backend_Controller.php
    ...
system/

[/quote]

This is not the default CI configuration. Am I also supposed to take the application/ folder out of system/?
#5

[eluser]SimonH[/eluser]
Hi,

I think what he means is by seperating your controllers into

application/controllers/frontend
and
application/controllers/backend

you should be able to share you resources just as well. I would really recommend using this approach especially if you are going to managing a lot of the data displayed on the frontend of your application. The main reason being that I have gone down the road of your first approach and it is a night mare to share any of your vital resources (models etc).
#6

[eluser]CodeIgniterNewbie[/eluser]
@simon - if I have:

application/controllers/frontend/login.php

How do I access it via the URL? Would it be like this: www.domain.com/frontend/login/? Wouldn't CI think that "login" is actually the first parameter of "frontend" controller (which isn't a controller in this case)?
#7

[eluser]SimonH[/eluser]
Hi,

it is my understanding that the routing algorithms used in CI are smart enough to figure this out. Hence the valid url the say application/frontend/customers/account would be www.domain.com/frontend/customers/account/some_method. Incase you would like to hide the fact that public visitors are on the "frontend" section of your application you could simply store the frontend related controllers directly in the application/controllers folder and keep the backend in the application/backend folder (I am assuming whoever you are building this application for will know that it is the backend they are accessing). You could however leave the frontend folder in place and use either some sort of routing mechansim or mod_rewrite rule to cut out the "frontend/..." in your urls (you would have to look into this matter yourself).

Hope this helps.
#8

[eluser]bubbafoley[/eluser]
You guys are on the right track. CodeIgniter allows you to put controllers in subdirectories and has a routing system to remap urls to controllers.

So if you have application/controllers/frontend/login.php

The real URL would be http://example.com/frontend/login.

You can easily make this url http://example.com/login with this route:

Code:
$route['login'] = 'frontend/login';

http://ellislab.com/codeigniter/user-gui...llers.html
http://ellislab.com/codeigniter/user-gui...uting.html
#9

[eluser]CodeIgniterNewbie[/eluser]
@bubbafoley, I thought putting controllers in sub-folders would cause problems (could've sworn this was the case a couple of years back when I tried this). Anyway, the sub-folders solution works for me. Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB