BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 This is the forum to discuss the Wrox book Professional CodeIgniter by Thomas Myer; ISBN: 9780470282458
Welcome to the p2p.wrox.com Forums . You are currently viewing the BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
February 15th, 2009, 08:17 AM
Registered User
Join Date: Nov 2008
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
CSV Import library for Products
Hi, i have problems with this operation. After the file is chosen and imported, we get on .../admin/products/import - But there is nothing displayed
There are no errors - simply pure screen
Any idea?
March 16th, 2009, 09:59 AM
Wrox Author
Join Date: May 2008
Location: Austin, TX, USA.
Posts: 53
Thanks: 0
Thanked 5 Times in 5 Posts
Can you provide more details? Perhaps a code dump of where you are going? or maybe a look at the data structure you are trying to pull in?
__________________
Thomas Myer
Author, Professional CodeIgniter
http://www.tripledogs.com
March 20th, 2009, 04:56 PM
Registered User
Join Date: Mar 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
I'm having the same issue, but several things I've discovered:
If your following the book
Code:
function importCsv()
should read when you load the library:
Code:
$this->load->library('CSVReader);
not
Code:
$this->load->library('CSVreader');
Then if you look in the CSVReader class you'll see the method is called parse_file not parseFile so the return statment should be
Code:
return $this->csvreader->parse_file($path)
not
Code:
return $this->csvreader->parseFile($path)
March 21st, 2009, 10:35 AM
Wrox Author
Join Date: May 2008
Location: Austin, TX, USA.
Posts: 53
Thanks: 0
Thanked 5 Times in 5 Posts
Here's what I have
In the code for CSVReader, I have:
Code:
class CSVReader {
var $fields; /** columns names retrieved after parsing */
var $separator = ','; /** separator used to explode each line */
function parseText($p_Text) {
$lines = explode("\n", $p_Text);
return $this->parseLines($lines);
}
function parseFile($p_Filepath) {
$lines = file($p_Filepath);
return $this->parseLines($lines);
}
function parseLines($p_CSVLines) {
$content = FALSE;
foreach( $p_CSVLines as $line_num => $line ) {
if( $line != '' ) { // skip empty lines
$elements = split($this->separator, $line);
if( !is_array($content) ) { // the first line contains fields names
$this->_fields = $elements;
$content = array();
} else {
$item = array();
foreach( $this->_fields as $id => $field ) {
$item[$field] = $elements[$id];
}
$content[] = $item;
}
}
}
return $content;
}
}
There's a parseFile() method in the class. Now here's the function in the MOrders model:
Code:
function importCsv(){
$config['upload_path'] = './csv/';
$config['allowed_types'] = 'csv';
$config['max_size'] = '2000';
$config['remove_spaces'] = true;
$config['overwrite'] = true;
$this->load->library('upload', $config);
$this->load->library('CSVReader');
if(!$this->upload->do_upload('csvfile')){
$this->upload->display_errors();
exit();
}
$csv = $this->upload->data();
$path = $csv['full_path'];
return $this->csvreader->parseFile($path);
}
In the model, I call the library properly "CSVReader" and the method too "parseFile($path)".
In the book, on page 199, I call the library improperly as "CSVreader". I'm not sure how it happened, but it happened. Sorry about that -- the code is correct, the example has the typo.
Now I'm wondering where the parse_file() thing came from, I can't find it anywhere.
__________________
Thomas Myer
Author, Professional CodeIgniter
http://www.tripledogs.com
April 28th, 2009, 06:26 AM
Registered User
Join Date: Apr 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
I'm having the same problem, after hours of bugs fixing and googling , i found this :
http://codeigniter.com/forums/viewthread/86033/#554404
I think the problem related to bug in FF3, because I got the following error :
Array( [error] => The filetype you are attempting to upload is not allowed.)
and parsing the upload data, i get :
Array( [dataup] => Array ( [file_name] => products_export.csv [file_type] => \"text/x-comma-separated-values\" [file_path] => D:/wwwroot/CodeIgniter/claudia/tmp/ [full_path] => D:/wwwroot/CodeIgniter/claudia/tmp/products_export.csv [raw_name] => products_export [orig_name] => [file_ext] => .csv [file_size] => 2.96 [is_image] => [image_width] => [image_height] => [image_type] => [image_size_str] => ))
Notice in : [file_type] => \"text/x-comma-separated-values\"
Try to test your code in internet explorer..
thx..
www.paulussetyo.com
April 28th, 2009, 06:30 AM
Registered User
Join Date: Apr 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
myerman
In the code for CSVReader, I have:
Now I'm wondering where the parse_file() thing came from, I can't find it anywhere.
If you download the latest CSVReader, the function should be : parse_file() not parsefile()
Thx
June 16th, 2009, 07:12 PM
Authorized User
Join Date: Jun 2009
Posts: 26
Thanks: 0
Thanked 1 Time in 1 Post
I think the empty page error due to that no "csv" folder was created in the CI root. That "csv" folder we need to create by ourselves, it is not included in the download. And you need to make that folder writable.
Last edited by blackhorse66; June 18th, 2009 at 12:47 AM .
August 5th, 2009, 09:55 PM
Registered User
Join Date: Jan 2004
Location: Tawau, Sbh, Malaysia.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
I am using FF 3.5.2, I also having the same problem, which is FF display
"The filetype you are attempting to upload is not allowed"
What I done is in config/mimes.php
I added one more array value,
'\"text/x-comma-separated-values\"'
Code:
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', '\"text/x-comma-separated-values\"'),
Then its work in FF 3.5.2, hope my reply can help you all.
__________________
Hi, Everyone!!!
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off