J2EE and CI

#11
[eluser]gon[/eluser]
You can, if you want, work with standard PHP classes including and instantiating them manually, so you can pass any argument to constructors.

For the models part, sometimes I write them as objects that can insert, update and select SETS of other objects which are the business entities:

Code:
// class that manages sets of Purchase objects

class Purchase_model extends Model {

    public function __construct() {
        parent::Model();
    }

    public get() {
        $query = $this->db->get('purchase');
        if ($query->num_rows() == 0) {
            return null;
        }
        $return_data = array();
        foreach ($query->result_array() as $purchase_row) {
             $return_data[] = new Purchase($purchase_row);
        }
        return $return_data;
    }
    public insert($purchases) {
        if (!is_array($purchases)) {
            $purchases = array($purchases);
        }
        
        $this->db->trans_start();

        foreach ($purchases as $purchase) {
             $purchase_row = array($purchase->get_info_as_array();
             $this->db->insert->('purchase', $purchase_row);                                  
        }
        if ($trans_status === false) {
             $this->db->trans_rollback();
             return false;
        } else {
             $this->db->trans_commit();
             return true;
        }
    }


    ............ more methods            
}

}

#12
[eluser]Rick Jolly[/eluser]
Welcome Corey S. I used Java before php as well.

I guess the question is: what value is a bean? You're example doesn't add any custom methods, so it doesn't offer any extra value. CI automatically creates objects (or arrays) from database results. That's saves writing and maintenance time.

#13
[eluser]akkumaru[/eluser]
,, i think we should try to think in a quite different way when using specific language,,,

in JAVA, the objects are the core of the application, this concept is so powerful and secure
in PHP, however the core is the algorithm behind the application, the functionality, i suppose. PHP does support the OOP, but that is not the main feature.

in JAVA each model/bean is 'alive', may be independent to one another,, but still, we have to write some 'logic' and 'functionality' on other JAVA models --e.g. to connect to the database and perform CRUD

in PHP CI, the array concept is so flexible, enough to act as a model/bean(in JAVA), while the logic and functionality may be implemented as the model(in CI) itself,,

what in my mind might be something like this:

Code:
class Person extends Model
{
   //...constructor

   function getPerson($id)
   {
      //..query from DB a person whose id = $id
      //..return a person record (as an array or an object)
   }

   function insertPerson($data)
   {
      // .. $data is an array, validate each element
      // .. perform insertion to DB
   }

   // .. other functionality
}

#14
[eluser]waterloomatt[/eluser]
Hi,

Sorry to revive an old thread. Have you, akkumaru & Corey S, found a solution that works for you? I'm from from a C# and JSP background too and I'm facing some OOP design irks ;-).

If you don't mind, how would you implement to following class diagram (see attachment). Please notice the multiplicity between the two classes. I don't need a detailed code example, just where you include your business objects (classes) and how you deal with multiplicity. In the Library folder? Or have you resigned yourselves to using Models as "objects"?

Cheers.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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