Welcome Guest, Not a member yet? Register   Sign In
How is CI intended to be used?
#1

[eluser]Unknown[/eluser]
Hi all,

I'm new to CodeIgniter. I've watched a few of the video tutorials but as they seem to deal only with the creation of a single application there's a few questions left unanswered for me.

Basically, if I have a site with a wide number of applications, how best do I structure that within CodeIgniter?

Do I create an overall 'application' that acts as the base website, and then each sub-application has its own directory within the view, controller and model of the CI install?

To simplify, I have a site that contains a bunch of popups that each provide a different service. If I were to convert the site to CI, what would be the best way of structuring it to aid in the speed of development of future popup applications? (They tend to share certain aspects such as CSS and some PHP.)

I hope I've got that across clearly enough! Apologies for the lack of specifics.
#2

[eluser]überfuzz[/eluser]
Are you planing to use MVC-structure? It's popular among developers right now.

My guess is that your unsure of what file structure you're going to use. First of all it's very common to place the application folder in the root.
A simple structure:
Quote:APPLICATION
config
config.php - place stuff like; meta info, title, paths to css
autoload.php
etc...
controllers
home.php
news.php
etc...
etc...
models
system.php - methods that get info from config.php
news.php - sql-querys to get latest news from sql.table
views
html_head.php - display; meta info, title, etc...
home.php - load(html_head.php), load(menu.php), display home in a nice html-way.
menu.php - nifty menu
etc...
ASSETS
css
style.css
js
layout - images
logo.gif
pictures
SYSTEM
...
I tend to use sub folders in controllers views etc. But don't let that bother you right now. Start building a test site and see what structure you like. Post questions that might appear.
#3

[eluser]Pr0v4[/eluser]
That make a lot of sense, but what's about if I wanna load from a controller a method present in another controller?
Let's put the idea in a project, for what i understood from the MVC every controller should have a scope, so i create these controllers:
Code:
controllers:
  -> site.php
  -> login.php
  -> users.php
  -> ...

The site.php will be in charge to show the website and for that sometime this have to borrow method from other controllers like a login form (from the login.php controller) or information about the user that has been signed up (from the users.php controller).

I'm new about programming in general, and most of all about MVC patterns, and I would like create my appllication starting with the right step!
#4

[eluser]jedd[/eluser]
[quote author="Pr0v4" date="1259276433"]
That make a lot of sense, but what's about if I wanna load from a controller a method present in another controller?
[/quote]

Then it indicates you have designed your application sub-optimally. Shared methods would reside either in a model (if they do modelly stuff) or in a library or helper (if that's appropriate), or MY_Controller (user-customisable parent to each Controller) or perhaps they don't need to exist as controller methods at all, but perhaps as per your example of a 'login form' it would actually be a view partial that's shared, not a controller method per se.

Quote:Let's put the idea in a project, for what i understood from the MVC every controller should have a scope, so i create these controllers:

Scope is an overloaded word. Every controller should manage a resource. A thing. A noun. Take your pick.

Quote:The site.php will be in charge to show the website and for that sometime this have to borrow method from other controllers like a login form (from the login.php controller) or information about the user that has been signed up (from the users.php controller).

Think instead of having each of your controllers being in charge of showing their little part of the web site.

You might redirect users to the User/login controller/method - rather than try to embed that HTML into other pages (though that's certainly quite possible within the MVC structure).
#5

[eluser]Phil Sturgeon[/eluser]
Think about using a modular structure. A module can then be a mini-aplpication on its own, with its own models, controllers, views, etc. I have a module for blog, users (contains logic, etc) and it keeps things separated.

If you need to run a method from another controller then redirect to it. You should not need to directly run another method from a controller as jedd mentioned there is always another way to do it.

All of my Admin controllers for example have their own type of MY_Controller (its extended again and called Admin_Controller, but now im probably just being confusing). In the constructor of this type of MY_Controller I have a call to the user library, which checks a user is a logged in admin, and if not redirects to login.

Between models, libraries and redirects you entirely cut out the need to directly call a controller method.




Theme © iAndrew 2016 - Forum software by © MyBB