Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Some questions while poking around in controllers, models, and forms...

ddumontddumont ✭✭
edited March 2011 in Vanilla 2.0 - 2.8
I see the rest style passing of parameters to the controllers and how that gets handled with the arguments to the particular controller method, but what about posting large amounts of data? or multi-part mime?

How can I read in data that's been posted that way, or by url args? file parts from a mime post?

There was an error rendering this rich post.

Comments

  • Options
    judgejjudgej
    edited March 2011
    There are plugins that handle instances of all these types of things, with code you can look at. I am no expert myself, but the basic gist is to create a form object and let that handle it all. Most plugins manage to do that in a few lines of code, plus a view to format the form.

    In orther words: it works by magic ;-) I do all those things you describe, but I have never had to explore the details of how it actually works.

    A good place to start is here, though this is by means comprehensive:

    http://www.vanillaforums.org/docs/models
  • Options
    Well I need to explore how it works :)
    My goal is to not have a visual form but to create a back-end service for another application.

    I'm about half way deep into forms now... I might create a model to see what kinds of things it will magically handle for me w.r.t. sql inserts. The documentation says models represent tables... I need to know if it's a 1:1 relationship, or if I can have a model that spans tables... and how that all works... :)

    There was an error rendering this rich post.

  • Options
    Though... starting to dig around it seems the form model might not be what I want to use for something like a rest service that doesn't have any notion of a visual display

    There was an error rendering this rich post.

  • Options
    Another question: I'd like to use the database driver in Garden... however it seems requesing the Gdn::Database doesn't do anything with passed in config... i guess since it's already been created.

    Am I all set creating a new Gdn_Database with my own config? What's the best way to do this?

    There was an error rendering this rich post.

  • Options
    @Lincoln, any ideas?

    There was an error rendering this rich post.

  • Options
    LincLinc Detroit Admin
    You want to use the database driver in a plugin? Or some other way?
  • Options
    In a controller. Right now I have a static member of my controller that stores the database. My init method opens the database with my options.

    I just want to make sure i'm not overly creating or underly creating database objects...
    I'm not really solid on the lifecycle of controllers.... and I'm not very proficient in php either :)

    There was an error rendering this rich post.

  • Options
    LincLinc Detroit Admin
    Typically you'd be using the database within a model, not a controller. A controller handles "business" logic of how the app operates, not interactions with the data.

    In a model, you simple use $this->SQL :) As long as your model extends Gdn_Model (it should) you'll "magically" have an SQL object ready to use.
  • Options
    Except that it's the Garden database :)
    I want to target another one.

    I also have tried using the model concept and it's a bit too restrictive for me as implemented. I'm actually not writing a UI, so the separation doesn't really apply so much here.

    There was an error rendering this rich post.

  • Options
    LincLinc Detroit Admin
    Maybe something like this?

    $DatabaseConfig['Engine'] = 'MySQL';
    $DatabaseConfig['Host'] = 'localhost';
    $DatabaseConfig['Dbname'] = 'dbname';
    $DatabaseConfig['User'] = 'dbuser';
    $DatabaseConfig['Password'] = 'dbpass';

    $this->Database = new Gdn_Database($DatabaseConfig);
    $this->SQL = $this->Database->SQL();
    $this->Construct = $this->Database->Structure();
  • Options
    LincLinc Detroit Admin
    Oh, I see what you did. "Gdn::Database" is a static reference to the singleton that already exists. You just want a whole new database object, like above.
  • Options
    Yeah I'm doing something like that :) so everything should be cool having it be a static member of my controller and creating the new gdn_database in my init method?

    There was an error rendering this rich post.

  • Options
    LincLinc Detroit Admin
    edited March 2011
    Yeah, I don't see why not. If you're going to be using the database object in lots of places you might want to register it with GardenFactory as a second singleton so you don't spawn a ton of db objects. (I think you can do that? I haven't tried it myself)
  • Options
    Good suggestion @Lincoln.

    @Tim, @Todd, @Mark How might I do that?

    There was an error rendering this rich post.

  • Options
    LincLinc Detroit Admin
    Outside of the plugin class, try something like this:

    (lifted from HtmLamed)
    Gdn::FactoryInstall('HtmlFormatter', 'HTMLawedPlugin', __FILE__, Gdn::FactorySingleton);
  • Options
    LincLinc Detroit Admin
    Bad example. Better would be to just look at the bootstrap creating a database:
    Gdn::FactoryInstall(Gdn::AliasDatabase, 'Gdn_Database', NULL, Gdn::FactorySingleton, array('Database'));
    So maybe call yours 'My_Database' or whatever instead.
  • Options
    Cool. I'll look at that.

    There was an error rendering this rich post.

  • Options
    Hey @Lincoln ,
    Just getting back to this now. I've been looking at the factory stuff in vanilla, and I'm a tad confused.
    /** @var boolean Whether or not Gdn::FactoryInstall should overwrite existing objects. */
    protected static $_FactoryOverwrite = TRUE;
    This looks like every time I register a factory, it will redefine it and blow away any previous definition.

    I'm still struggling to understand the lifecycle of variables in php. Is there no way to create and reference a singleton across all requests? In java I could have a static class member that all transaction threads could reference.

    @Todd can you shed any light on this?

    There was an error rendering this rich post.

Sign In or Register to comment.