Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
ORM - different concept
  • I hope this is not too off-topic... I was using my own framework previously (as everyone else I guess) and I can't help but compare it to FuelPHP. One thing that I miss most is the kind-of-ORM I had. I would like to explain the idea if I may - I would appreciate some pointers if such thing already exists. What I did was I created classes for each data type, but not data type in DB sense, but more in "type of data that is saved here" sense. For instance, I had "email", "file", "image", "text", "lineOfText", "choice", "flag" and similar datatypes. Each datatype knew how to handle validation, creating its DB fields, inserting and updating in DB. And for "image" datatype it created thumbnails, resized images, added watermarks,... all based on a supplied array of settings. Another role was to prepare the variables for display engine (Smarty). Specification of field looked like this:
    $fields = array (
      "email" => array (
        "type" => "email",
        "formAsk" => "Enter your e-mail:",
        "optional" => true,
      ),
      "myimage" => array (
        "type" => "image",
        "formAsk" => "Upload your image:",
        "path" => "myimages/thumb/"
        "resize" => array (
          "mode" => "maxxy",
          "limitX" => 200, 
          "limitY" => 150, 
        ),
      ),
    );
    
    The above code is all that is needed to make a form for inserting email + image, validate both, display errors if validation failed, resize image if needed, save in DB,... Note that this is DB agnostic - developer doesn't need to know about the underlying engine (but can of course change anything if he so wishes). The system proved very efficient and allowed fast form creation with minimal chance of validation problems - I have used it for the last 15 years and have succesfully solved very different problems with it. It would need a rebuild now though, which is the reason I am moving to another framework. If I understand correctly, ORM packages don't allow this level of abstraction - am I correct? Would it be interesting for FuelPHP to add this kind of abstraction? As I said, I would appreciate some pointers or ideas. The original idea was mine so I don't even know if it is a known concept (I presume it is though) and how it is called - I guess ORM is too broad term for it?
  • Hmmm, I wasn't clear enough - I know that, but I was wondering if there already exists implementation of such (or similar) design and what would be the best way to use it with FuelPHP (if it exists)? This design basically provides an easy way of building potentially complex Models, so it could arguably fall under "ORM" paradigm as I understand it... I might be wrong here though. :)
  • ORM models map directly to database tables, and allows you to access them in an OOP manner. The models you describe are functional abstraction classes, which do follow the idea of M in MVC, but are entirely different from the ORM models. My point was that nobody is stopping you from creating generic models for some functionality in your application, and from them, use ORM models to access the database. From a Fuel point of view, a class is a class, there is no technical difference between classes, controllers and models, apart from the way they are named.
  • Thanks, WanWizard - I appreciate it! I have actually found something quite similar to what I wanted - Fieldsets. I just need to "envelop" them in my classes that are datatype-aware and it should be fairly easy to do what I want. Now if i could just find a good tutorial on Fieldsets... ;) Thanks again and happy coding! :)
    P.S.: btw., these smileys are a bit weird... Can I suggest somebody changes line 64 in http://fuelphp.com/addons/shared_addons/themes/fuel/css/global.css to:
    #content img, #content_side img {
      background-color:#FFFFFF;
      border:1px solid #DBDBDB;
      float:none;
      margin:0 10px 0 0;
      padding:5px;
    }
    
    Still not perfect, but way better.
  • Our designer is aware of the flaws of this theme, but hasn't had time to fix them...
  • The ORM is an object oriented way of accessing your database, which is something completely different to what you are describing. Nobody is stopping you from creating classes based on this design. There is nothing in Fuel that prevents you from doing so. These classes in turn can use ORM models to store data in a database table.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion