How to use the lithium Linux framework with the listed collection list and changing the collection in the model

I want to use a lithium framework to create my application configuration interface, because I like its minimal approach and document-oriented storage model (e.g. Mongodb).

However (and I know that it has not yet been released), there is little information, tutorials or examples to move you from a simple blogging tutorial.

What I'm trying to do now is to create an application that will show me the collections that I have in Mongodb, and then let me work with the collection that I select. I can't seem to understand:

a) how would I build a model that lists collections - preferably in accordance with my internal naming scheme,

b) How can I break the agreement model to indicate the name of the collection used?

I think that there are two things that I come across in order to answer these two questions - perhaps a fundamental misunderstanding of how to move a model in MVC beyond the scope of simple model-model management model examples, and secondly, the actual process of telling the source mongo data on which collection to use.

any pointers or examples gratefully received.

Chris

update ::

So, I figured out how to install the collection - for reference, you can set the source in the $ _meta array as follows:

protected $_meta = array(
    'source' => '<<collectionName>>'
);

still don’t know how to use a model that will show me all the collections that I have in my database. Any ideas how to do this from a philosophical or technological point of view?

further update ::

. , . :

<?php
namespace app\models;
use lithium\data\Model;

class Posts extends \lithium\data\Model{

    protected $_meta = array('source' => false);

    public function testcolls(){
        return (self::connection()->sources());
    }
}
?>

, , :

<?php foreach ($post->testcolls() as $coll): ?>
    <h2><?=$coll ?></h2>
<?php endforeach; ?>

, , , - " " , , , find. , . .

, , , find .

:

class Dataqueues extends \lithium\data\Model{

    protected $_meta = array('source' => false);

    public static function find($filter, array $options = array()) {
        if (isset($options['collection'])){
            self::meta('source', $options['collection']);
        }
        return parent::find('all',$options);
    }   
}

:

class DataqueuesController extends \lithium\action\Controller {

    public function index() {
        $dataqueues = Dataqueues::find('all',array('limit'=>20,'collection'=>'W501'));
        return compact('dataqueues');
    }
}

, , :

class Collections extends \lithium\data\Model{

    protected $_meta = array('source' => false);

    public static function find($filter, array $options = array()) {

        return self::connection()->sources();
    }   
}

, .

+3
2

Collections, $_meta['source'] = false, .

YourModel::connection()->sources(), .
(): http://li3.me/docs/lithium/data/source/MongoDb::sources(). listCollections() MongoDB http://php.net/manual/en/mongodb.listcollections.php

Model:: find(), , , Collections::find('all', array('conditions' => ..., 'collection' => 'foo'))... , : -)

, !

+3

, .

:

: '' = > '< < collectionName → '

: , .
IE: "" "".

, :

connections.php \bootstrap\connections.php. , , , . . http://li3.me/docs/manual/quickstart. :

// MongoDB Connection
Connections::add('default', array('type' =>  'MongoDb', 'database' => 'blog', 'host' => 'localhost'));

,
, , :

$model = Models::all();

- , , Models - . .
, . . http://li3.me/docs/manual/working-with-data/using-models.wiki

, , :

return compact('model', 'model2', 'model3');

, . 2 3, , , , .

, $model , . , - . : $model:

foreach ($model as $aModel) {
    echo $aModel;
}

. : http://li3.me/docs/manual/handling-http-requests/views.wiki

, .

0

All Articles