Yii Framework Forum: [Extension] Mongoyii - Yii Framework Forum

Jump to content

  • (6 Pages)
  • +
  • « First
  • 4
  • 5
  • 6
  • You cannot start a new topic
  • You cannot reply to this topic

[Extension] Mongoyii Rate Topic: -----

#101 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 24-June 11

Posted 20 December 2013 - 04:45 AM

Ok I am gonna have to dig into this when I get a moments chance cos that should have worked.
0

#102 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 24-June 11

Posted 21 December 2013 - 11:32 AM

Sorry for the lateness but I did finally get round to test this and it works for me.

Using the latest version of MongoYii I used this in the siteController in the test repository:

 		$u=new User();
 		$u->username='gjgjgjg';
 		$u->email='sdfdfdsfdsfdsf';
 		$u->password='dffdsfsf';
 		$u->ex_sub['title'] = 'sub ';
 		$u->validate();
var_dump($u);


with this in the model:

			array('ex_sub', 'subdocument', 'type' => 'one', 'rules' => array(
            	array('title', 'filter', 'filter' => 'trim')
        	)),


And after validation I get this value for the subdocument title field:

  public 'ex_sub' => 
    array
      'title' => string 'sub' (length=3)


As you can see it has been trimmed.

I decided to take it a step further and add this to the model:

			array('ex_sub', 'subdocument', 'type' => 'one', 'rules' => array(
            	array('title', 'filter', 'filter' => function($c){
				return new MongoId();        		
				})
        	)),


What I get in the var_dump is:

  public 'ex_sub' => 
    array
      'title' => 
        object(MongoId)[30]
          public '$id' => string '52b5c1f06803fafb06f2cef2' (length=24)


So this is working perfectly for me.

It should be noted that the line that produces these var_dumps is of course the one in the sitecontroller var_dumping the user model after validation.

Can you show some var_dumps and that?
0

#103 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 24-June 11

Posted 21 December 2013 - 11:38 AM

I should note that because I have actually tested the fix I did as working now I have pushed it to the 3.1.5 tag on GitHub
0

#104 User is offline   elke 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 26-July 13

Posted 21 December 2013 - 04:27 PM

Thank you for looking into this problem. I'll try again on Monday, when I'm at work. It seems it should have worked for me as well. Sorry if I bothered you for nothing.
0

#105 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 24-June 11

Posted 21 December 2013 - 04:28 PM

Its ok, better to get the help and be sure something works than sit there endless wondering :)
0

#106 User is offline   NetDabbler 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 17-January 12

Posted 09 June 2014 - 10:24 AM

Hi all,
I'm having great difficulty getting a search() function to work.

The index.php works fine but the $model->search() call in admin.php is returning nothing. I've only one document in one collection in Mongo. My code is very similar to Vivi's on the previous page so I'm puzzled about why it isn't working.

Does anyone know where I've went wrong?

UPDATE: If I create the EMongoDataProvider with an empty $criteria array then I get data returned, but as expected the filter does not work. This is very strange...

 
return new EMongoDataProvider($this, array('criteria' => array(),));


Here is my code:

	
class MUser extends EMongoDocument {
...
        public function rules()
	{
		return array(
			 array('username', 'required'),
			 array('username', 'length', 'max'=>20),
			 array('_id, username', 'safe', 'on'=>'search'),
		);
	}
...
	public function search()
	{
		$criteria=new EMongoCriteria();
		$criteria->compare('_id',$this->_id);
		$criteria->compare('username',$this->username, true);
		return new EMongoDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}


and controller

class MUserController extends Controller
...
        public function actionIndex()
	{
		$dataProvider=new EMongoDataProvider('MUser');
		$this->render('index',array(
			'dataProvider'=>$dataProvider,
		));
	}
...
	public function actionAdmin()
	{
		$model=new MUser('search');
		$model->unsetAttributes();  // clear any default values
		if (isset($_GET['MUser'])) {		
			$model->attributes=$_GET['MUser'];
		}
		$this->render('admin',array(
			'model'=>$model,
		));
	}


and index.php

$this->widget('bootstrap.widgets.TbListView',array(
	'dataProvider'=>$dataProvider,
	'itemView'=>'_view',
));


and admin.php

<?php $this->widget('bootstrap.widgets.TbGridView',array(
	'id'=>'user-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'columns'=>array(
		'_id',
		'username',	
		array(
			'class'=>'bootstrap.widgets.TbButtonColumn',
		),
	),
)); ?>


Thanks, ND.
0

#107 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 24-June 11

Posted 12 June 2014 - 03:25 AM

Sorry for not replying in a timely manner, was very busy when I notified of this reply and the forum isn't very good at reminding you of things.

Anyway, did you get this solved?
0

#108 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 24-June 11

Posted 12 June 2014 - 03:56 AM

Ha, I have this problem too, it is not understanding that username is empty as such shouldn't use it, seems like a quick fix
0

#109 User is offline   Sammaye 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 24-June 11

Posted 12 June 2014 - 04:01 AM

Ok I can't fix this, instead you will need to work around it with:

if($this->username){
$criteria->compare('username', $this->username, true);
}

currently.

The reason for this is because I actually have a line in the compare function that does:

if($value === null){
$query[$column] = null;

Right at the beginning, this is a problem and Yii1 does not actually do this, it ignores null values but I added this and it (reportedly) is used in quite a few projects as such taking it out could...break a lot of things.

So currently, you need to check if something is set first.
0

Share this topic:


  • (6 Pages)
  • +
  • « First
  • 4
  • 5
  • 6
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users