Part of the EllisLab Network
   
 
Parser sub-arrays :/
Posted: 26 February 2007 09:33 AM   [ Ignore ]  
Summer Student
Total Posts:  3
Joined  02-26-2007

Hey. I’ve found a bug in the parser library. I have an array, with 3 sub-arrays. I pass it to the parser, but for some reason the output from the parser isn’t what it should be at all. I have appeneded the array structure, template contents, and output to help you debug:


Array structure:

Array
(
    
[gear_list] => Array
        (
            
[1] => Array
                (
                    
[id] => 1
                    [name]
=> Banana Gun
                    [brand]
=> Banana Brand
                    [primary]
=> 1
                
)

            
[2] => Array
                (
                    
[id] => 2
                    [name]
=> Funky Spunky
                    [brand]
=> Banana Brand
                    [primary]
=> 1
                
)

            
[3] => Array
                (
                    
[id] => 3
                    [name]
=> Hamburger Launcher
                    [brand]
=> Banana Brand
                    [primary]
=> 0
                
)

        )
)

Relevant code from template:

{gear_list}
  
<tr>
    <
td>{id}</td>
    <
td>{brand}</td>
    <
td>{name}</td>
    <
td>{primary}</td>
  </
tr>
{/gear_list}

and finally, our output:

3     Banana Brand     Hamburger Launcher     0
3     Banana Brand     Hamburger Launcher     0
3     Banana Brand     Hamburger Launcher     0

It seems to be only pulling the last index from our array! :D


Thanks,
  monokrome.

Profile
 
 
Posted: 26 February 2007 10:42 AM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  351
Joined  07-25-2006

What do you mean by parser library?

 Signature 

me and some random code, hosted by dh. and a blog too! ++ dead bugs

Profile
 
 
Posted: 26 February 2007 11:20 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Total Posts:  3
Joined  02-26-2007

Exactly what I said… The parser library.

$this->load->library('parser');

In the user guide, it is referred to as the Template Parser Library.

Profile
 
 
Posted: 27 February 2007 02:15 PM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  486
Joined  09-14-2006

Welcome to CI, monokrome. I’ve not experienced this myself. Could you give some details about your PHP and CI versions.

 Signature 

Code Igniter 1.5.4 / CentOS 5 / PHP 5.2.3 / Apache 2.2.2 / MySQL 5.0.27

Profile
 
 
Posted: 27 February 2007 07:14 PM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  3
Joined  02-26-2007

I am using the newest CI, with apache2 and PHP5.

Profile
 
 
Posted: 27 February 2007 08:39 PM   [ Ignore ]   [ # 5 ]  
Research Assistant
RankRankRank
Total Posts:  404
Joined  02-14-2007

I have nothing to contribute, other than I know using arrays within arrays with the template parser library is a bear—it’s a much more tedious process than it should be.  I think I remember running into this same bug before I threw my hands up in disgust and went to just using php in my views.

Profile
 
 
Posted: 27 February 2007 10:45 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
RankRankRank
Total Posts:  915
Joined  07-10-2006
Vanceone - 27 February 2007 08:39 PM

I have nothing to contribute, other than I know using arrays within arrays with the template parser library is a bear—it’s a much more tedious process than it should be.  I think I remember running into this same bug before I threw my hands up in disgust and went to just using php in my views.

The wizard that Joeles is will probably come up with a solution out of thin air, but my head still hurts after banging my head against the wall for similar reasons. This thread, I will watch. I used bTemplate on the last two projects, but am using the PHP approach on my current project intermixed with some ideas from Savant which is a PHP-based template solution.

Profile
 
 
Posted: 27 February 2007 11:40 PM   [ Ignore ]   [ # 7 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  486
Joined  09-14-2006

esra is so good for my ego… smile

monokrome, I’m unable to duplicate your issue. I’m using a fresh install of CI on PHP5 and Apache 2. Here’s the code I used.

Controller:

class Welcome extends Controller {

    
function index()
    
{
        $this
->load->library('parser');

        
$data['gear_list'] = array (
            array (
                
'id' => 1,
                
'name' => 'Banana Gun',
                
'brand' => 'Banana Brand',
                
'primary' => 1
            
),
            array (
                
'id' => 2,
                
'name' => 'Funky Spunky',
                
'brand' => 'Banana Brand',
                
'primary' => 1
            
),
            array (
                
'id' => 3,
                
'name' => 'Hamburger Launcher',
                
'brand' => 'Banana Brand',
                
'primary' => 0
            
)
        );

        
$this->parser->parse('welcome_message', $data);
    
}
}

View:

<table>
{gear_list}
  
<tr>
    <
td>{id}</td>
    <
td>{brand}</td>
    <
td>{name}</td>
    <
td>{primary}</td>
  </
tr>
{/gear_list}
</table>

Output:

1     Banana Brand     Banana Gun             1
2     Banana Brand     Funky Spunky           1
3     Banana Brand     Hamburger Launcher     0

 Signature 

Code Igniter 1.5.4 / CentOS 5 / PHP 5.2.3 / Apache 2.2.2 / MySQL 5.0.27

Profile
 
 
Posted: 28 February 2007 12:31 AM   [ Ignore ]   [ # 8 ]  
Research Assistant
RankRankRank
Total Posts:  915
Joined  07-10-2006

Joeles… my wife begs to differ from your wife. She is one of those oddballs (sorry if you read this) who writes device drivers (printer drivers, scanner drivers, etc.) and low-level firmware code (for things like GPS receivers and semiconductor instrumentation) usually using Microsoft assember (masm) or in some cases C. When I look over her shoulder, everything is in 3-letter function names and calls to registers and stacks. Algorithm is her middle name. It’s all like greek to me. She started this genius stuff. And I quote “He could make a bundle in high-level tech support because he explains difficult-to-understand concepts in simple terms”. In thirty years of marriage, I’ve never heard her compliment anyone like that, so take that for what its worth. Unfortunately, she’s useless around here because she feels the need to dissect CI code in a very slow and tedious way before doing anything useful (sorry again if you read this). She checks this forum about 30 times a day, but I’ve yet to see her post. When I asked her why, she said that she wasn’t ready yet, so only god know what’s coming down the pike.

Profile
 
 
Posted: 28 February 2007 02:24 AM   [ Ignore ]   [ # 9 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  207
Joined  12-22-2006
esra - 28 February 2007 12:31 AM

Joeles… my wife begs to differ from your wife. She is one of those oddballs (sorry if you read this) who writes device drivers (printer drivers, scanner drivers, etc.) and low-level firmware code (for things like GPS receivers and semiconductor instrumentation) usually using Microsoft assember (masm) or in some cases C. When I look over her shoulder, everything is in 3-letter function names and calls to registers and stacks. Algorithm is her middle name. It’s all like greek to me. She started this genius stuff. And I quote “He could make a bundle in high-level tech support because he explains difficult-to-understand concepts in simple terms”. In thirty years of marriage, I’ve never heard her compliment anyone like that, so take that for what its worth. Unfortunately, she’s useless around here because she feels the need to dissect CI code in a very slow and tedious way before doing anything useful (sorry again if you read this). She checks this forum about 30 times a day, but I’ve yet to see her post. When I asked her why, she said that she wasn’t ready yet, so only god know what’s coming down the pike.

Wow… I am impressed by your wife… She must be a smarty one raspberry Can’t wait to see what she starts todo when she is “ready”.

Profile
 
 
Posted: 28 February 2007 12:35 PM   [ Ignore ]   [ # 10 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  486
Joined  09-14-2006

Wow, that’s really flattering coming from someone with her background. Tell her thanks. Like her, I visited for several months before my first post, but after that, I haven’t been able to stop. I still maintain, however, that I’m not that bright. I’m almost entirely self-taught so I just try to explain things and offer examples that I would understand if I were just starting.

 Signature 

Code Igniter 1.5.4 / CentOS 5 / PHP 5.2.3 / Apache 2.2.2 / MySQL 5.0.27

Profile
 
 
Posted: 28 February 2007 01:25 PM   [ Ignore ]   [ # 11 ]  
Research Assistant
RankRankRank
Total Posts:  970
Joined  04-13-2006
esra - 28 February 2007 12:31 AM

Joeles… my wife begs to differ from your wife. She is one of those oddballs (sorry if you read this) who writes device drivers (printer drivers, scanner drivers, etc.) and low-level firmware code (for things like GPS receivers and semiconductor instrumentation) usually using Microsoft assember (masm) or in some cases C. When I look over her shoulder, everything is in 3-letter function names and calls to registers and stacks. Algorithm is her middle name.

Ah yes, but can she make a nice casserole?

Profile
 
 
Posted: 28 February 2007 09:31 PM   [ Ignore ]   [ # 12 ]  
Research Assistant
RankRankRank
Total Posts:  404
Joined  02-14-2007

While I agree that Joeles is great, My suspicion is that the op issue involves having other variables besides just the array in the view.  I’m sure it works if all you have is the array, but my vague memory of this issue was that I had other variables, and then tried to toss in this array somewhere (in the context of populating some tables).  So, I had a table heading, some username variables, then tried to build the table using the parser—it didn’t work. 

And yeah, Joeles is fantastic—sounds like esra’s wife is too!

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 66431 Total Logged-in Users: 27
Total Topics: 84795 Total Anonymous Users: 0
Total Replies: 455080 Total Guests: 230
Total Posts: 539875    
Members ( View Memberlist )
Newest Members:  GlennJDylan1978X_franbaguasllogocsaturkeyPeter BryanttherendStudioGeorgiaJZeer