Yii Framework Forum: csvout install problem - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

csvout install problem Rate Topic: -----

#1 User is offline   Darkfly 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 04-September 09

Posted 06 September 2009 - 11:04 AM

Another problem installing one extension:

I have installed csvout extensions like this:

1- I copy all the 'csv' folder under /protected/extensions


2-I add to my /protected/config/main.php file:
'controllerMap'=>array(
'csv'=>array(
'class'=>'application.extensions.csv.CsvController',
'property1'=>'value1',
'property2'=>'value2',
),
),

before the 'components'=>array(...' part

3-In the Admin form of my windows i put:

<?php $this->widget('application.extensions.csv.csvWidget', array(
'table' => '.dataGrid',
'csvFile' => ''));
?>

4- when i click to export list to CSV i have:

proprieties "CsvController.property1" not define.
c:\projects\yii\framework\YiiBase.php(191)
00179: {
00180: unset($args[0]);
00181: $class=new ReflectionClass($type);
00182: // Note: ReflectionClass::newInstanceArgs() is available for PHP 5.1.3+
00183: // $object=$class->newInstanceArgs($args);
00184: $object=call_user_func_array(array($class,'newInstance'),$args);
00185: }
00186: }
00187: else
00188: $object=new $type;
00189:
00190: foreach($config as $key=>$value)
00191: $object->$key=$value;
00192:
00193: return $object;
00194: }




I try to:

In main.php change:
'controllerMap'=>array(
'csv'=>array(
'class'=>'application.extensions.csv.CsvController',
'property1'=>'value1',
'property2'=>'value2',
),
),
to:
'controllerMap'=>array(
'csv'=>array(
'class'=>'application.extensions.csv.CsvController',
'table' => '.dataGrid',
'csvFile' => '',
),
),
but i have a similar problem "proprieties "CsvController.table" not define."

Any idea? Some people use csvout?

Thanks
0

#2 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 07 September 2009 - 01:24 AM

View PostDarkfly, on 06 September 2009 - 11:04 AM, said:

Another problem installing one extension:

I have installed csvout extensions like this:

1- I copy all the 'csv' folder under /protected/extensions


2-I add to my /protected/config/main.php file:
'controllerMap'=>array(
'csv'=>array(
'class'=>'application.extensions.csv.CsvController',
'property1'=>'value1',
'property2'=>'value2',
),
),

before the 'components'=>array(...' part

3-In the Admin form of my windows i put:

<?php $this->widget('application.extensions.csv.csvWidget', array(
'table' => '.dataGrid',
'csvFile' => ''));
?>

4- when i click to export list to CSV i have:

...

Any idea? Some people use csvout?

Thanks


Darkfly, csvout documentation contains 'property1'=>'value1', 'property2'=>'value2' only as example of setting other properties for CsvController class. And 'property1' / 'property2' are not real properties.

For simplest case you need to add to /protected/config/main.php:
'controllerMap'=>array(
              'csv'=>array(
                  'class'=>'application.extensions.csv.CsvController',
                  //here you can set other properties for CsvController object  
                  ),
     ),


And add to view:
$this->widget('application.extensions.csv.csvWidget', 
   //here you can set other properties for CsvWidget object
);

0

#3 User is offline   Darkfly 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 04-September 09

Posted 07 September 2009 - 10:51 AM

Ok thanks for the help, is exporting now.

But i have a problem, when i click in export bouton, i have one file called "data.csv" but in this export file, i have:

"" <a href="/nova/index.php?r=terceiros/admin&amp;sort=id">Id</a>;<a href="/nova/index.php?r=terceiros/admin&amp;sort=tipo">Tipo</a>;<a href="/nova/index.php?r=terceiros/admin&amp;sort=nome">Nome</a>;<a href="/nova/index.php?r=terceiros/admin&amp;sort=contacto">Contacto</a>;<a href="/nova/index.php?r=terceiros/admin&amp;sort=email">Email</a>;<a href="/nova/index.php?r=terceiros/admin&amp;sort=nif">Nif</a>;<a href="/nova/index.php?r=terceiros/admin&amp;sort=nib">Nib</a>;<a href="/nova/index.php?r=terceiros/admin&amp;sort=agencia_id">Agência</a>;Actions
<a href="/nova/index.php?r=terceiros/show&amp;id=1">1</a>;1;Limpa tudo lda;;;;;Agência1;<center>
<a href="/nova/index.php?r=terceiros/update&amp;id=1"><img src="images/edit2.png" alt="Modificar" border="0" height="25" width="25"></a>

"


this is the HTML code i have in the TALBE (<table class="dataGrid" id="table">), not the coluns export like i expect...

i use this code in the view page:

<?php $this->widget('application.extensions.csv.csvWidget', array(
'table' => '.dataGrid',
'csvFile' => ''));
?>
before the table (i try after too)....

Why i have the export in html format and not csv?
0

#4 User is offline   Darkfly 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 04-September 09

Posted 07 September 2009 - 02:29 PM

Sorry,i don't see the review in the extension page, i have to change the widget function to not output the A tag.

I change the fonction with:

if(cells[k].firstChild.nodeName.toLowerCase()!=='a'){
input.setAttribute('value', cells[k].innerHTML);
} else {
input.setAttribute('value', cells[k].firstChild.innerHTML);
}


but with this code, nothing append when i click in the csv export button.

I try the orignal code of function,and change only:
input.setAttribute('value', cells[k].innerHTML);
to
input.setAttribute('value', cells[k].firstChild.innerHTML);

and nothing append when i click in button

if i change back to
input.setAttribute('value', cells[k].innerHTML);
the csv open, but with <a html code....

The part "firstChild" seems to be the cause of the problem.... but why?
0

#5 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 08 September 2009 - 01:51 AM

View PostDarkfly, on 07 September 2009 - 02:29 PM, said:

I try the orignal code of function,and change only:
input.setAttribute('value', cells[k].innerHTML);
to
input.setAttribute('value', cells[k].firstChild.innerHTML);


Try this code:
//check if cell contains a link
if((!cells[k].firstChild) || (cells[k].firstChild.nodeName.toLowerCase()!=='a')){
    input.setAttribute('value', cells[k].innerHTML);
} else {
    input.setAttribute('value', cells[k].firstChild.innerHTML);
}


I attached also my (modified) version of csv extension: Attached File  csv.zip (5K)
Number of downloads: 48.
This version can export all table data regardless of pagination (current version exports only visible data).
To export all data you need to disable pagination in your controller code if "format" parameter is given:
    /**
     * Manages all models.
     */
    public function actionAdmin()
    {
        $criteria=new CDbCriteria;

        ...

        $format = Yii::app()->request->getParam('format');

        $pages=new CPagination(User::model()->count($criteria));
        $pages->pageSize= self::PAGE_SIZE;

        //if format is set - no pagination
        if (!isset($format)) {
            $pages->applyLimit($criteria);
        }

        $sort=new ExtSort('User');
        $sort->defaultOrder = "lname";
        $sort->applyOrder($criteria);

        $models=User::model()->findAll($criteria);

        $params = array(
                'models'=>$models,
                'pages'=>$pages,
                'sort'=>$sort,
                ...,
                'format'=>isset($format)?$format:''
        );
      
        if (Yii::app()->request->isAjaxRequest) {
            $this->renderPartial('adminList', $params);
        } else {
            $this->render('admin', $params);
        }
    }

0

#6 User is offline   Darkfly 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 04-September 09

Posted 08 September 2009 - 06:12 AM

Thanks Seb is working now with this code:

//check if cell contains a link
if((!cells[k].firstChild) || (cells[k].firstChild.nodeName.toLowerCase()!=='a')){
input.setAttribute('value', cells[k].innerHTML);
} else {
input.setAttribute('value', cells[k].firstChild.innerHTML);
}

i try your csv.zip too, and is working, i have only one problem to include the JQuery UI, because of the "dialog" you use to the export message
i have added in the widget code:
$this->widget('application.extensions.jui.EJqueryUiInclude', array('theme'=>'humanity'));

after that all is working.

Many Thanks for the help.
0

#7 User is offline   Ahyo Haryanto 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 21-May 09
  • Location:Yogyakarta Indonesia

Posted 04 October 2009 - 05:31 PM

what's wrong with me. i just had downloaded csv.zip above, and then:
1. extract them into extentions directory
2. added this script into config/main.php :
'controllerMap'=>array(
    'csv'=>array(
        'class'=>'application.extensions.csv.CsvController',
	'table' => '.dataGrid',
	'csvFile' => ''),
),

3. and then added this script into views/user/admin :
<?php $this->widget('application.extensions.csv.csvWidget', array(
'table' => '.dataGrid',
'csvFile' => ''));
?>

4. and also modified my userController :
public function actionAdmin()
{
	$this->processAdminCommand();

	$criteria=new CDbCriteria;
	 
	$filters = new CDataFilter(user::model());
        $filters->addFilter(new CFilterSearch('userFieldsSearch', 'Filter :'));
        $filters->applyCriteria($criteria);

        $pages=new CPagination(user::model()->count($criteria));
        $pages->pageSize=self::PAGE_SIZE;
		
	$format = Yii::app()->request->getParam('format');
		
        //if format is set - no pagination
        if (!isset($format)) {
            $pages->applyLimit($criteria);
        }
		
	$sort=new CSort('user');
        $sort->defaultOrder = "username";
        $sort->applyOrder($criteria);

	/* 
        i have no Extsort here, is this custom sort ?
	$sort=new ExtSort('user');
	$sort->applyOrder($criteria);
	*/

        $models=user::model()->findAll($criteria);
		
	$params = array(
                'models'=>$models,
                'pages'=>$pages,
                'sort'=>$sort,
                'filters'=>$filters,
                'format'=>isset($format)?$format:''
        );
      
        if (Yii::app()->request->isAjaxRequest) {
            $this->renderPartial('adminList', $params);
        } else {
            $this->render('admin', $params);
        }
        
	}

is there somethings wrong ? it did't response anything when i clicked export button.
thanks before.
Open Source? Open Mind!
0

#8 User is offline   Darkfly 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 04-September 09

Posted 05 October 2009 - 03:40 PM

You have a error in main.php:

For simplest case you need to add to /protected/config/main.php:
'controllerMap'=>array(
'csv'=>array(
'class'=>'application.extensions.csv.CsvController',
//here you can set other properties for CsvController object
),
),

youv don't need to put :
'table' => '.dataGrid',
'csvFile' => ''),

in main.php.

and read the post from begining, if you have over problems.
0

#9 User is offline   Ahyo Haryanto 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 21-May 09
  • Location:Yogyakarta Indonesia

Posted 05 October 2009 - 04:34 PM

View PostDarkfly, on 05 October 2009 - 03:40 PM, said:

You have a error in main.php:

For simplest case you need to add to /protected/config/main.php:
'controllerMap'=>array(
'csv'=>array(
'class'=>'application.extensions.csv.CsvController',
//here you can set other properties for CsvController object
),
),

youv don't need to put :
'table' => '.dataGrid',
'csvFile' => ''),

in main.php.

and read the post from begining, if you have over problems.

thanks Darkfly, but it still not working for me.
i had changed my controllerMap in main.php to :
'controllerMap'=>array(
		'csv'=>array(
		'class'=>'application.extensions.csv.CsvController',
		//here you can set other properties for CsvController object
		),
	),

i think map controller just mapping the real controler directory webapp/protected/controller to our path custom right?. so i don't need controllerMap if i just copied CsvController.php into webapp/protected/controller.
i guest my problem just on the JQuery. here is my source code from firefox selection source:
 <a onclick="return exportToCsv();" href="#"><img src="/gts2009/assets/8c4f6571/csv.gif" class="img_link" title="export"></a>
<script type="text/javascript">
/*<![CDATA[*/
                
                var formCsv;

                function makeCsvData()
                {
                    formCsv = $('#csvExportForm').get(0);                    
                    arrayEl = $('#csvExportData .dataGrid').get();
                    for (var i=0; i<arrayEl.length; i++) {
                        rows = arrayEl[i].rows;
                        for (var j=0; j<rows.length; j++){
                            if (rows[j].className.indexOf('filterRow') === -1) {
                                cells = rows[j].cells;
                                for (var k=0; k<cells.length; k++){
                                    if (cells[k].className.indexOf('actionCol') === -1) {
                                        var input = document.createElement('input');
                                        input.setAttribute('type', 'hidden');
                                        input.setAttribute('name', 'tCells['+i+']['+j+']['+k+']');
                                        //check if cell contains a link
                                        if((!cells[k].firstChild) || (cells[k].firstChild.nodeName.toLowerCase()!=='a')){
                                            input.setAttribute('value', cells[k].innerHTML);
                                        } else {
                                            input.setAttribute('value', cells[k].firstChild.innerHTML);
                                        }
                                        formCsv.appendChild(input);
                                    }
                                }
                            }
                        }
                    }
                    input = document.createElement('input');
                    input.setAttribute('type', 'hidden');
                    input.setAttribute('name', 'csvFile');
                    input.setAttribute('value', 'data.csv');
                    formCsv.appendChild(input);
                }

                function exportToCsv()
                {
                    $('<div id="csvExportData" style="visibility:hidden"></>').appendTo('body');
                    $('<div id="exportDialogContent" style="margin:0 40px;display:block;"></div>').appendTo('body');
                    $('<form id="csvExportForm" method="POST" action="/gts2009/index.php/csv/index.html"></form>').appendTo('body');
                    
                    $('#exportDialogContent').html('<span><img src="/css/loading.gif" style="vertical-align:middle;"> Exporting data ...</span>');
                    
                    $('#exportDialogContent').dialog(
                    {
                        title: 'Export to CSV',
                        dialogClass: 'export-dialog',                        
                        autoOpen: false,                        
                        position: 'center',                        
                        resizable: false,
                        height:46,
                        minHeight:40

                    }
                    );
                    $('.export-dialog .ui-dialog-titlebar').hide();
                    $('.export-dialog').css('opacity', '0.5');
                    $('#exportDialogContent').dialog('open');

                    
                    jQuery.ajax(
                            {'type':'POST','url':window.location.href,'cache':false,
                                'data':'format=csv',
                                'success':function(html) {
                                    jQuery('#csvExportData').html(html);
                                    makeCsvData();
                                    formCsv.submit();
                                    $('#exportDialogContent').dialog('destroy');
                                    jQuery('#csvExportData').remove();
                                    jQuery('#exportDialogContent').remove();
                                    jQuery('#csvExportForm').html('');
                                    return false;
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    $('#exportDialogContent').html('Can not export data, status: ' + textStatus);
                                    $('.export-dialog .ui-dialog-titlebar').show();
                                    $('.export-dialog').css('opacity', '1');
                                    $('#exportDialogContent').dialog('option', 'buttons', { 'Close': function() { $('#exportDialogContent').dialog('destroy'); } });
                                }
                            }
                    );                                               
                    
                    return false;
                }
            
/*]]>*/
</script>

it's rather hard to debug on web apps. :D
Open Source? Open Mind!
0

#10 User is offline   Ahyo Haryanto 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 21-May 09
  • Location:Yogyakarta Indonesia

Posted 06 October 2009 - 05:12 AM

i'm trying to build a new clear yii webapp.
1. setting db connection.
2. created model and crud. using yiic.
3. extract csv to extentions dir
4. modified main.php
5. added widget into admin view
but it still not working.
the only good things i saw the "Exporting data ..." on my screen when i clicked export button.
but nothings data to exported.
it makes me so confused. :(

Attached File(s)


Open Source? Open Mind!
0

#11 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 07 October 2009 - 01:41 PM

View Postpegel.linuxs, on 06 October 2009 - 05:12 AM, said:

i'm trying to build a new clear yii webapp.
1. setting db connection.
2. created model and crud. using yiic.
3. extract csv to extentions dir
4. modified main.php
5. added widget into admin view
but it still not working.
the only good things i saw the "Exporting data ..." on my screen when i clicked export button.
but nothings data to exported.
it makes me so confused. :(


Hi, pegel.linuxs

Do you still have this problem? Can you attach sources of your demo application?
Also try to make export while having FireBug console open - you should see whether export request is successfully processed on server side or not.
Another way to find our what is wrong is to use php debugger (I am using netbeans + xdebug).

Regards, Seb
0

#12 User is offline   Ahyo Haryanto 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 21-May 09
  • Location:Yogyakarta Indonesia

Posted 08 October 2009 - 05:32 PM

View Postseb, on 07 October 2009 - 01:41 PM, said:

Hi, pegel.linuxs

Do you still have this problem? Can you attach sources of your demo application?
Also try to make export while having FireBug console open - you should see whether export request is successfully processed on server side or not.
Another way to find our what is wrong is to use php debugger (I am using netbeans + xdebug).

Regards, Seb


an error occured using firebug was like this
$("#exportDialogContent").dialog is not a function
exportToCsv()index.ph...ser/admin (line 87)
function onclick(event) { return exportToCsv(); }(click clientX=303, clientY=161)index.ph...ent/seq/1 (line 2)
[Break on this error] minHeight:40\n


here you are :

Attached File(s)

  • Attached File  yi.zip (29.35K)
    Number of downloads: 12

Open Source? Open Mind!
0

#13 User is offline   seb 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 29-June 09

Posted 09 October 2009 - 01:50 AM

An error was because my version of csvout was dependent on jQuery Dialog (for ajax "loading" indicator). Now I changed csvout code and removed that dependency, Attached File  csv.zip (6.04K)
Number of downloads: 55).

I also attached working version of your demo app, Attached File  csv_app.zip (32.59K)
Number of downloads: 66.
0

#14 User is offline   Ahyo Haryanto 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 24
  • Joined: 21-May 09
  • Location:Yogyakarta Indonesia

Posted 09 October 2009 - 05:19 AM

View Postseb, on 09 October 2009 - 01:50 AM, said:

An error was because my version of csvout was dependent on jQuery Dialog (for ajax "loading" indicator). Now I changed csvout code and removed that dependency, Attachment csv.zip).

I also attached working version of your demo app, Attachment csv_app.zip.


thank's a lot seb, it works fine for me now.

i would change the header for exporting to word/excel apps.
i had made it in simple way.
header("Content-type: application/msword"); (ms word)
header("Content-type: application/vns.ms-excel"); (ms excel)
Open Source? Open Mind!
0

#15 User is offline   spamec 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 36
  • Joined: 19-February 09

Posted 08 February 2010 - 12:29 PM

Hi everyone, extension works just great :) Do you have any ideas how to support colspan in table (as rowspan is too dificult). I tried to modify makeCsvData where form input is created, but results are horrible ;)

Simple empty cells after, when td has colspan would be enough...
0

#16 User is offline   rianday 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 16-December 10

Posted 11 January 2011 - 10:50 PM

View Postseb, on 09 October 2009 - 01:50 AM, said:

An error was because my version of csvout was dependent on jQuery Dialog (for ajax "loading" indicator). Now I changed csvout code and removed that dependency, Attachment csv.zip).

I also attached working version of your demo app, Attachment csv_app.zip.


i have yhe solution for export file to csv.. thanks full for your example.. btw are u from indonesia??
0

Share this topic:


Page 1 of 1
  • 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