Search And Pagnation Without Any List Widget

Goal:

My goal is to get pagnation and a search function with a foreach statment.

Why?

Abel to use the models search function.

Not be lockt to any list widget.

Dont build criterias and other logic at more done one place.

My try: :)


		$model=new Invoice('search');

		$model->unsetAttributes();  // clear any default values

		if(isset($_GET['Invoice'])){

			$model->attributes=$_GET['Invoice'];

		}

		$model->companyId = $this->getCompany()->id;

		$model->type = 0; // kund fakturer




		$criteria=$model->search();

	

	

		$count=Invoice::model()->count($criteria);

		$pages=new CPagination($count);

	

		// results per page

		$pages->pageSize=10;

		$pages->applyLimit($criteria);

		$data=Invoice::model()->findAll($criteria);




		$this->render('/struktur/invoice/index',array(

			'invoices'=>$data,

			'invoice'=>$model,

			'pages'=>$pages

		));

This results in the error: "Object of class CActiveDataProvider could not be converted to string"

If i


print_r($model->search())

i get an array with the CDbCriteria object:


 

...

CDbCriteria Object ( [select] => * [distinct] => [condition] => (companyId=:ycp0) AND (fakturaNr LIKE :ycp1) [params] => Array ( [:ycp0] => 92 [:ycp1] => %1337% ) [limit] => -1 [offset] => -1 [order] => [group] => [join] => [having] => [with] => [alias] => [together] => [index] => [scopes] => [_e:private] => [_m:private] => ) [_id:private] => Invoice [_data:private] => [_keys:private] => [_totalItemCount:private] => [_sort:private] => [_pagination:private] => [_e:private] => [_m:private] => )

If i look in CDbCommandBuilder.php, and function,


public function createCountCommand($table,$criteria,$alias='t')

And i make


print_r($criteria);

i get this result


CDbCriteria Object

(

    [select] => *

    [distinct] => 

    [condition] => CActiveDataProvider Object

        (

            [modelClass] => Invoice

            [model] => Invoice Object

                (

                    [_md:private] => CActiveRecordMetaData Object

                        (

                            [tableSchema] => CMysqlTableSchema Object

                                (

                                    [schemaName] => 

                                    [name] => tbl_invoice

                                    [rawName] => `tbl_invoice`

                                    [primaryKey] => id

                                    [sequenceName] => 

                                    [foreignKeys] => Array

                                        (

                                        )


                                    [columns] => Array

                                        (

...

So the criteria is created but the condition strangle converts to a CActiveDataProvider Object.

so why does this CDbCriteria object dosent work as criteria?

Any ideas?

thanks

found, it!


$criteria=$model->search()->criteria

[SOLVED][/SOLVED]