Attention: We have experienced a large volume of forum spam that none of the Vanilla Forums anti-spam add-ons have managed to fix. Until we have the time to migrate to another forum platform, membership is invite-only. Please send me an email with a short message so I know you're human and I'll send an invite your way :) You can also use our chat room to post questions.

Thanks for your patience,
Johnny B, Lead Developer of Elefant
documentation for the query() function
  • Is there some documentation somewhere for the query() function? I don't just mean suggestions about how to use it in one setting or another, I mean a complete explanation of the function and its parameters. I don't know if there is a generic MVC query() function or if Elefant's is somehow unique.

  • The query() method really just returns a fresh model object with no existing data assigned to it, with the option of specifying the fields to be returned. From there, you can chain methods like where() or_where() order() group() and one of the fetch() methods that actually executes the query that the others are building. Let me know if you meant all those methods or if you were just wondering about query() itself.

    Here's the API doc link to it:

    http://jbroadway.github.com/elefant/api/Model.html#section-24

    (although I can see API docs need to be updated!)

    And here are the three ways of using that method:

    <?php
    
    // No parameters, fetches all fields
    // e.g., select * from `mymodel` where `field1` = ?
    $res = MyModel::query ()
        ->where ('field1', 'value')
        ->fetch ();
    
    // Fields as a string
    // e.g., select field1, field2 from `mymodel` where `field1` = ?
    $res = MyModel::query ('field1, field2')
        ->where ('field1', 'value')
        ->fetch ();
    
    // Fields as an array (preferred method)
    // e.g., select `field1`, `field2` from `mymodel` where `field1` = ?
    $res = MyModel::query (array ('field1', 'field2'))
        ->where ('field1', 'value')
        ->fetch ();
    
    ?>
    
  • Very helpful, thank you!

  • I think the doc is missing a few lines. The code for insert and update are missing their first lines (which I presume should be):

    public function insert () {

    and

    public function update () {

    respectively.

  • Using your reply as a model, I guessed that there might be documentation for $page at http://jbroadway.github.com/elefant/api/Page.html. Woo hoo, there is! However I don't know how I might have found either of these pages through the existing navigation. Can you point me to their parent pages?

  • Found it: http://www.elefantcms.com/wiki/API-reference However this page is a bit out of date. Perhaps Phrocco needs to be run again.

  • The API references page is here:

    http://www.elefantcms.com/wiki/API-reference

    There's also a little "Jump to..." link in the top-right corner of the API pages, but it's easy to miss. I've been meaning to switch to a different API generator, I think the navigation could be better and the output could be easier to follow too.

  • The 'insert' and 'update' are confusing, those are comments from the source that are pulled into the left column for reference, but they're not docblock style comments so they really shouldn't be... Really time to look at other API generators :)

    There's no insert() or update() method, just put() that handles both. Sorry for the confusion there.

Howdy, Stranger!

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

Note: You can use Markdown formatting in your comments.