• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
(Help needed) How to create plug and play applications with CI

#1
[eluser]navetz[/eluser]
Okay so I am very new to CodeIgniter but I think I've got most of the basics down. I am also new to a python framework called django.

In the tutorials for django it you use MVC to create plug and play applications that if you design them to be loosely couple from other applications, can be simply plugged into another django project.

My question is: How do you do this with CodeIgniter?

The way it works in django: You have a url script in your root directory that tells the web server where the applications are (similar to the route).

When you get into your application directory you look at your application url script file and that will tell you how to manage your url's for this application.

Example:

In / you have URL that says whenver you go to /polls/ load the poll application url script.

Then the url script in your /polls/ application folder would be the equivalent of the route script.

This might be unclear because I have not used either CodeIgniter or Django for any real project yet and I don't fully understand how everything works. Let me know if something needs clarification.

#2
[eluser]bretticus[/eluser]
[quote author="navetz" date="1253535139"]
In the tutorials for django it you use MVC to create plug and play applications that if you design them to be loosely couple from other applications, can be simply plugged into another django project.[/quote]

plug and play is nice "marketing" but in reality that is the goal of object oriented programming. That is, abstract your tools as much as possible (loose coupling.) I suppose you might equate these to libraries in Codeigniter (which is a more traditional term not hidden behind a fluffy name.)

You'll find that codeigniter (or just about any MVC framework) fits this pattern for the most part. For example, you can certainly take controllers from any Codeigniter project and incorporate them into another project. Sure, you'd change the views but the functionality can be the same. Again this is true of any MVC framework for the most part (if not certainly the goal of MVC.) And, yes, it should be clear from the blog videos (or the manual) that Codeigniter also uses the convention-over-configuration model for accessing code within your project (just like pretty much all other MVC frameworks.)

django (and even CakePHP if you want a PHP example) have command line applications to automate code building. Codeigniter is just pure framework. So if you're into automation, you might not be into Codeigniter (me, on the other hand, like it for being lightweight and simplistic.)

#3
[eluser]navetz[/eluser]
Is CakePHP the closest framework to django? I don't think I'll switch from CI because I really like it so far but I might give it a shot.

As for the ability to plug and play I am not just talking about the library class files.

I would like to be able to just copy and paste an application directory for a certain app into another CI project and just configure the urls to point to that particular application. That way all my Models Views and Controllers for one application would be kept in that directory. You could even include specific media files in there - css, js, images.

This would make it a lot easier to port around instead of having to move each specific thing (models , controllers, specific views, css, images, js) for each project.

#4
[eluser]BrianDHall[/eluser]
Oh, CI does this by default to the point that we don't even have a name for it - its just how CI works. Your CI "application" directory can be renamed easily, as can the CI core files.

What I do is move my system (core CI files) library up out of the web root so many applications can share the same library (and it makes upgrading to new versions of CI really easy and safe), and I rename my applications file so I can easily have multiple folders.

From my index.php file:

Code:
/*
|---------------------------------------------------------------
| SYSTEM FOLDER NAME
|---------------------------------------------------------------
|
| This variable must contain the name of your "system" folder.
| Include the path if the folder is not in the same  directory
| as this file.
|
| NO TRAILING SLASH!
|
*/
    $system_folder = "../ci-1_7_2";

/*
|---------------------------------------------------------------
| APPLICATION FOLDER NAME
|---------------------------------------------------------------
|
| If you want this front controller to use a different "application"
| folder then the default one you can set its name here. The folder
| can also be renamed or relocated anywhere on your server.
| For more info please see the user guide:
| http://ellislab.com/codeigniter/user-guide/general/managing_apps.html
|
|
| NO TRAILING SLASH!
|
*/
    $application_folder = "rentlist";

Now, to install another 'application' you just make a new directory, stick its own index.php and files in there, configure the index.php to point to the CI sytem folder (where ever you put it or named it), and make sure your .htaccess file won't interfere with the new application.

One CI application doesn't know the other exists. In this way you can control a logically infinate amount of sites and applications using one core installation of CI. "Plug and Play" is so integral to how CI works that we don't think to even mention that it works that way.

#5
[eluser]navetz[/eluser]
[quote author="BrianDHall" date="1253557693"]
Now, to install another 'application' you just make a new directory, stick its own index.php and files in there, configure the index.php to point to the CI sytem folder (where ever you put it or named it), and make sure your .htaccess file won't interfere with the new application.
[/quote]

Sorry I am being a bit of a noob here but what do you mean by stick its own index.php and files in there? The only index.php file I have is at the root of my CI folder. Also what files are you talking about? Only the application files or am I including all the system files.

#6
[eluser]BrianDHall[/eluser]
Sorry, I was being loose with my wording there and using too many different words interchangably.

OK, CI by default comes with a "system" folder and an index.php in the zip distribution. This index.php is the front-end controller, and the one that you customize to give the path of the 'system' folder and the 'application' folder.

Inside the system folder you can pull out the 'application' folder entirely and move it somewhere else, even rename it - just put its path relative to the index.php front-end controller file previously mentioned.

You can then rename the system folder (minus the application folder you removed, of course) and move it too - again with the proviso that you give the proper relative path to index.php front-end controller.

In this way you can have two or more applications that all use the same 'core files' or 'system folder' - and that system folder can also be moved up out of the web document root if you should want to.

Many of us think that CI should come this way by default, but its not a big deal to move it around a bit to fit our particular inclinations.

#7
[eluser]navetz[/eluser]
Oh wow that is exactly what I am looking for!

It would be great if CI came this way, I think it would help users create more loosely coupled code.

#8
[eluser]BrianDHall[/eluser]
Yeah, it would be a little more obvious that this was a feature if they distributed it a touch different, but luckily its very easy to configure.

I do this with all my CI projects now because it makes upgrading so painless. I make a system folder with the version number of CI and put it above my public html documents on my server, then all my applications just refer to that. When a new version comes out, or if for some reason I need to check out an SVN version, I put it in a new folder and then I only change my old applications to use the new folder once I'm sure nothing breaks when doing so.

Its not very highly touted because CI is so small to begin with (just a few MB) and its already super easy to install. Its also not designed for security to allow different users to use the same core installation of CI but preventing them from accessing an application that isn't there (again, a feature that's rather unnecessary with a footprint so small as CI has). Still, it's a useful tool most advanced CI developers seem to utilize.

#9
[eluser]navetz[/eluser]
After trying what you told me I now understand what you were showing me. I did a poor job wording my question. I posted a new topic with specific details.

http://ellislab.com/forums/viewthread/129847/


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.