Howdy, Stranger!

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

Sign In with Google Sign In with OpenID

documentation for the query() function

edited March 2012 in Documentation

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:

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

    And here are the three ways of using that method:

    // 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!

  • edited March 2012

    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 () {


    public function update () {


  • Using your reply as a model, I guessed that there might be documentation for $page at 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: However this page is a bit out of date. Perhaps Phrocco needs to be run again.

  • The API references page is here:

    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.

Sign In or Register to comment.