search method implement of EMongoDocument seems to not work #56

Open
yiqing-95 opened this Issue Sep 22, 2011 · 4 comments

Comments

Projects
None yet
5 participants

hi canni :
i use the gii generate the views , but in admin view , there come out some exception :

Fatal error: Call to a member function getDbCriteria() on a non-object in C:\xampp\htdocs\my\livmx\protected\extensions\YiiMongoDbSuite\EMongoDocumentDataProvider.php on line 73

you can check the EMongoDocument and admin view , i don't know the reason but this two place seems to be mess:
/**
* Magic search method, provides basic search functionality.
*
* Returns EMongoDocument object ($this) with criteria set to
* rexexp: /$attributeValue/i
* used for Data provider search functionality
* @param boolean $caseSensitive whathever do a case-sensitive search, default to false
* @return EMongoDocument
* @SInCE v1.2.2
*/
public function search($caseSensitive = false)
{
$criteria = $this->getDbCriteria();

    foreach($this->getSafeAttributeNames() as $attribute)
    {
        if($this->$attribute !== null && $this->$attribute !== '')
        {
            if(is_array($this->$attribute) || is_object($this->$attribute))
                $criteria->$attribute = $this->$attribute;
            else if(preg_match('/^(?:\s*(<>|<=|>=|<|>|=|!=|==))?(.*)$/',$this->$attribute,$matches))
            {
                $op = $matches[1];
                $value = $matches[2];

                if($op === '=') $op = '==';

                if($op !== '')
                    call_user_func(array($criteria, $attribute), $op, is_numeric($value) ? floatval($value) : $value);
                else
                    $criteria->$attribute = new MongoRegex($caseSensitive ? '/'.$this->$attribute.'/' : '/'.$this->$attribute.'/i');
            }
        }
    }

    $this->setDbCriteria($criteria);

    return new EMongoDocumentDataProvider($this);
}

you comment : Returns EMongoDocument object ($this) with criteria set to
but the end of the method witch return an instance of EMongoDocmentDataProvider;

in the admin view :

widget('zii.widgets.grid.CGridView', array( 'id'=>'product-type-attr-grid', 'dataProvider'=>new EMongoDocumentDataProvider($model->search(), array( 'sort'=>array( 'attributes'=>array( 'productTypeName', 'inputType', 'dataType', 'modelAttribute', 'label', 'value', /* 'items', 'htmlOptions', '_id', */ ), ), )), so you see :)

TheHett commented Jul 1, 2012

I have the same problem

The problem is with ADMIN view (I am guessing you used Gii generator for CRUD)
'dataProvider'=>new blah blah
Should be
'dataProvider'=>$model->search(),

Thanks!

Hi Canni,
It will be good if you can help us to make admin workable using mongodb.it will be great

Thanks in advance

Same problem occur with me. I have solved this by doing following steps:

  1. Goto file YiiMongoDbSuite\EMongoDocument.php find function name search() do this in it:
    //return new EMongoDocumentDataProvider($this);
    return new $this;
  1. Now in admin view do this:
'dataProvider'=>new EMongoDocumentDataProvider($model->search(), array(
    'criteria'=>$model->getDbCriteria()
    //.....
    ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment