It uses much the same setup as Yii but nested within the root document in array form. Hmmm, it seems that the error summary cannot just take a plain array which kinda sucks.
I might need to write an additional little function some where that can do what CHtml cannot.
CHtml::errorSummary() is designed to take instances of CModel, and EMongoModel extends from that class, hence it has getErrors() which is what errorSummary() use. What is the problem, can you not give it an instance of EMongoModel?
Also, I’d like to point out that EMongoModel shouldn’t override getErrors() since it doesn’t do anything that the parent equivalent doesn’t do. Removing this (and potentially other overriding methods that does the same thing as parent) can clean up the class a bit
The problem is that subdocuments are not enclosed in EMongoModel classes, they are simply arrays and the error summary functions do not recognise array nesting for errors.
Yea, however, if you check the comments above it you will realise that I added a new method which modified a private variable in the parent. PHP OO accession works in such a way that if you want to modify a parent variable directly that is of private scope you cannot. You have to duplicate all the code associated with that var whose functionality you wish to keep.
The only way to add errors to the var atm from the parent instance is to assume you are adding a message to a field and nothing else I don’t think, unless you mean something else?
To let people know, I will most likely start to remake MongoYii for Yii2 in the coming weeks/months (depending on how long it takes for the Yii team to say that the API etc is not going to change).
So I have full intention of porting MongoYii in its current form, hopefully without breaking too much, to Yii2
Due to how MongoDB works that won’t get a cursor but instead a MongoCollection object. This is fundamentally how the PHP driver works. If you want a MongoCursor to return you will need to use a read function like find or findOne
Yes it will only return a MongoCursor, what exactly are you trying to return? If you are trying to return all results from that collection then you can try iterator_to_array($cursor)
That made it! I didn’t even know about what iterators where. Gonna read more about it.
But, in another way how could I get that data without doing this? (as it was not mentioned elsewhere, I suppose there is another way of getting this data into a Yii view for example)
Thanks!
(by the way, I would recommend you to add a small note about it in the project Wiki and/or Github to help people that were looking specifically for this)
I’m trying to migrate from MySQL (ActiveRecord) to MongoDB using MongoYii and I found that saveAttributes($attributes) method does not work like it does in AR. It should “save a selected list of attributes”, where $attributes are “attributes to be updated”.
But in MongoYii, saveAttributes() erases all other attributes which are not passed to this method.
class EMongoDocument extends EMongoModel{
public function saveAttributes($attributes) {
...
return $this->updateByPk($this->{$this->primaryKey()}, $values);
In my opinion, it should work like in update() method:
class EMongoDocument extends EMongoModel{
public function update($attributes=null) {
...
$this->lastError = $this->updateByPk($this->{$this->primaryKey()}, array('$set' => $attributes));