Welcome Guest, Not a member yet? Register   Sign In
About file organization in CodeIgniter - Sobre la organización de archivos en CodeIgniter
#1

[eluser]Unknown[/eluser]
Hola a tod@s,
Estoy empezando con el framework Codeigniter y me he decidido a pasar mi web a CodeIgniter, por la flexibilidad que ello supone, la facilidad al programar nuevos módulos y por la reutilización de código, además de la seguridad que caracteriza CodeIgniter según he podido ver.

Pues bien, necesito un par de consejos sobre organización de los ficheros, y sobre "en qué transformar" cada fichero de mi web actual.

Os explico, mi web actual es un juego de fútbol en donde cada usuario puede tener su equipo, sus jugadores y puede inscribirse en una liga junto con otros 19 jugadores (20 jugadores en la liga en total), pues bien los archivos que utilizo son los siguientes:

- Clases:
.user.class.php
.league.class.php
.player.class.php
.market.class.php
.bid.class.php
.board.class.php

Ok, estas clases serían la "estructura de datos" de la aplicación, luego tengo una carpeta con funciones que utilizan estas clases y que la relacionan con la base de datos:

- Funciones:
.user_functions.php
.league_functions.php
.market_functions.php
.board_functions.php
...

Estas funciones son las que se conectan a la base de datos, recogen los datos e instancian objetos de las clases de arriba, por ejemplo player_new(2) nos crearía un objeto Player con los datos del player de id = 2 de la base de datos.

Es decir, que estas funciones son las que utilizan las clases de arriba.

Pues bien, necesito saber la "traducción" de esto en CodeIgniter, ¿dónde organizo las clases? He estado informándome un poco sobre CodeIgniter y he visto que lo que más se acerca a las funciones que comento son los Modelos que son los encargados de recibir y enviar datos de la base de datos. Pero yo necesito acceder a estas funciones desde cualquier sección de mi página, es decir, no sólo un modelo por controlador.

Por otro lado, otra cuestión: Mi web usa AJAX , así que las peticiones ajax ahora las gestionaba desde un único archivo. ¿Cómo tendría que hacerlo con CodeIgniter? ¿Cada petición dirigida a un controlador diferente? ¿O podría , por ejemplo tener un controlador que se encargue de recibir todas las peticiones ajax y de distribuirlas por los controladores encargados del procesamiento de cada petición?

Muchas gracias de antemano,
Un saludo!

-------------------------------
ENGLISH
Hi everyone,
I'm starting with the CI framework and I decided to "convert my web to CodeIgniter", for the flexibility that entails, easy to program new modules and code reuse, in addition to security features that CodeIgniter has as I have seen.

Well, I need a couple of tips for organizing the files, and on "how to transform" every file of my current website.

I mean, my site now is a football game where each user can have their team, their players and can join a league along with 19 other players (20 players in the league in total), as well the files I use are the following:

- Classes:
. User.class.php
. League.class.php
. Player.class.php
. Market.class.php
. Bid.class.php
. Board.class.php

Ok, these classes would be "data structure" of the application, then I have a folder with functions that use these classes and relate it to the database:

- Functions:
. User_functions.php
. League_functions.php
. Market_functions.php
. Board_functions.php
...

These functions are those that connect to the database, collect data and instantiate objects from the classes above, such player_new (2) we create an object with the information of the player id = 2 in the database.

So I need to know the "translation" of this in CodeIgniter, where classes organized? I've been learning a little about CodeIgniter and I've seen that the closest thing to the features I mention are the models, that are responsible for receiving and sending data from the database. But I need to access these functions from any section of my site, not only a model per controller.

On the other hand, another question: My site uses AJAX, so the ajax requests are now managed from a single file. How should I do it with CodeIgniter? every request to a different controller? Or for example, Can I have a controller that is responsible of receiving all ajax requests and distributing them to the controllers that will process each request?

Thank you very much in advance !
And sorry for my poor english...
#2

[eluser]toopay[/eluser]
Put your "data structure" (if you called it like that) in controllers folder, and convert them into CI controller's pattern, then put your database/connectivity files into models folder and convert then into CI model's pattern.

About ajax stuff, put in on library, then you can use it on your controller.
#3

[eluser]n0xie[/eluser]
Quote:But I need to access these functions from any section of my site, not only a model per controller.
You can access models from several controllers. You can access several models per controller.
#4

[eluser]Unknown[/eluser]
Oks I'll do that, thank you very much guys.




Theme © iAndrew 2016 - Forum software by © MyBB