J2EE and CI

#1
[eluser]akkumaru[/eluser]
i've implemented MVC with J2EE before,,
with no framewrok, a standard J2EE application with servlet, JSP, and JavaBeans,,

when i start with CI, some things make me confused,,
have anyone ever compared J2EE and CI,,? please explain it to me,,


related question:
how do i make a JavaClass-like class in CI,,??
i do not mean a controller,
i mean a class which contains the application algorithm,, does the 'dirty works',, contains data and function,,

i've tried this using the 'library', but i've got problems when i put the file inside a folder,,
and i used the 'model' as interface to the database, so i avoid writing complex code in it,,

thank you for responses

#2
[eluser]Sam Dark[/eluser]
You can embed logic related to data in a model or use your own classes if models aren't enough for you.

#3
[eluser]Colin Williams[/eluser]
You made not one reference to PHP in your post, so I think you might want to understand PHP first before using CI. Then the User Guide is, well, your guide.

#4
[eluser]narkaT[/eluser]
[quote author="akkumaru" date="1224694649"i mean a class which contains the application algorithm,, does the 'dirty works',, contains data and function,,[/quote]

thats not what i would call MVC.
the "dirty work" is done by the model, the controller coordinates the
"dirty work" and makes sure the right view is used to display data.

the controller and the model are both classes.

correct me if I'm wrong Smile

#5
[eluser]Colin Williams[/eluser]
I actually think that sometimes the Controller's work is a bit dirty, especially when a lot of actors (many models, many views, many libraries, advanced validation, etc) are involved. But I would agree that generally it is the Model that shares the burden--does the dirty work--to keep the rest of the app clean.

#6
[eluser]akkumaru[/eluser]
it is true that i don't have much experience with PHP,,
i suppose there wouldn't be much difference when i use the OOP feature either in Java or PHP,,
but i may be wrong,, and i still think in JAVA instead of PHP,,

i think i need to rephrase my question: :cheese:
how do i make a java-like class in CI,,?

,,,
if i implement a class as model, how do i pass variables to the constructor?
if i implement a class as library, how do i access 'the class variables'?

@Sam Dark
yes, i intend to use my own class,,then where should i put it? in models or libraries, or,,,?
and how do i 'use' it? do i have to load it first?

i've read the user guide section:library,, but i don't have my questions answered, yet,,
i really appreciate your answers,,

#7
[eluser]Sam Dark[/eluser]
akkumaru
Using native CodeIgniter Model you can't pass anything to it's constructor. Actually you can… but without using native CodeIgniter $this->load->model or implementing your own loader:

Code:
$model = new MyCoolModel($param1, $param2);

If you'll implement your functionality in the library you can pass some parameters in an associative array via second argument in $this->load->library().

To access properties in PHP you need them to be public like in Java:
Code:
class MyClass {
  public $myvar;
  var $myvar; // PHP4 way of doing it
}

About putting your own class into CI structure… if it interacts with your data (DB, filesystem) then it's a model. If it's utility class like RSS reader / Caching frontend etc. — it's a library. Also you just can use your classes without actually putting them in CI.

#8
[eluser]narkaT[/eluser]
[quote author="akkumaru" date="1224765413"]how do i make a java-like class in CI,,?[/quote]

specify "java-like"?
as far is I can remember writing classes in java wasn't that different
from writing php classes Wink


[quote author="akkumaru" date="1224765413"]if i implement a class as model, how do i pass variables to the constructor?[/quote]
as sam said that isn't possible when using the native model-loading mechanism.
but you could pass the parameter's to a method, after loading the model.

[quote author="akkumaru" date="1224765413"]if i implement a class as library, how do i access 'the class variables'?[/quote]
library's are userful when you want a certain "low-level"-functionality that
assists you when writing your application-code.
for example, if you want a session library that utilizes the native php sessions
to store data.

#9
[eluser]akkumaru[/eluser]
thank you,,
i think i got the answer now,, :cheese:

by the way,, i can not put a library-class in a folder, can i ?

#10
[eluser]Unknown[/eluser]
I have to jump in and agree with the confusion on this usage of a Model. Also coming from the Java world, I am used to beans being set up as so:

Code:
public class Person implements Serializable {

    private String firstName = null;
    private String lastName = null;

    public Person (String firstName, String lastName) {
        setFirstName(firstName);
        setLastName(lastName);
    }
    
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
        
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    
    public String getLastName() {
        return this.lastName;
    }
        
    public String getFirstName() {
        return this.firstName;
    }
    
}


So in a Java based MVC world, the Model objects (the beans) are instantiated, optionally manipulated by the Controller and then passed to the View for usage. To me, the Model here is just another "container" to do what I would consider data-level logic.

The hard part for me is to not think of them as true instance objects where I can instantiate a set of CI model instances. For example, if I am understanding this correctly, I cannot $this->load multiple Person objects (supposing I have a CI version of what I have above) and manipulate them as individuals. Rather, I can use the model objects to retrieve sets of data and the like.

Perhaps I would use the Model concept here to generate an array of object instances and have the model return that to my Controller? If this is a viable solution, how would one do it while also being CI friendly?

Am I completely off base here with this notion?


I will admit I am a complete newbie here, but CI has been great to pick up and start learning so far. I started out with CakePHP and I really didn't feel comfortable with their baking and whatnot... :coolsmile:


Thanks!
Corey


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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