Welcome Guest, Not a member yet? Register   Sign In
Template parser class and multilevel arrays
#1

[eluser]Unknown[/eluser]
Hi Everybody first of all i am new here, so hi.

i am currently working on my first ci project, which will be a order management software.

i am having some problems understanding how to access multilevel arrays with the template parser

i have the following code:
Code:
...
{airports}
   {country_name}
   {airport_name}
   {airport_code}
{/airports}

...


i know it is not formatted or anything like that,
now the array which i am passing look like this

Code:
[19] => Array
        (
            [id] => 6816
            [airport_code] => PIK
            [airport_name] => Preswick
            [country_code] =>
            [airport_vip] => 350
            [connection_vip] =>
            [customs_access] =>
            [max_people] => 5
            [extra_pax] => 45
            [fast_track] =>
            [airplane_transit] =>
            [countries] => Array
                (
                    [id] => 1
                    [country_code] => GB
                    [country_name] => United Kingdom
                )

        )

as you can see country name is inside countries, how would i access it with the template parser?

* i forgot to mention that all the other variables were showing correctly for each item of the array. only the country name doesn't show up
#2

[eluser]bretticus[/eluser]
I have no idea if template parser is recursive, but you have tried something like?

Code:
{airports}
   {country_name}
   {airport_name}
   {airport_code}
   {countries}
      {country_name}
   {/countries}
{/airports}

I'm not sure I would use the CI parser class at all really. It's pretty limited if you need any layout logic (yes, good to avoid but not always possible.) I prefer good 'ole views (because I can use any PHP code I want.) However, if you anticipate you may need more control in your templates, you might want to use a template parser like Smarty.
#3

[eluser]Unknown[/eluser]
Yes, gave me some errors....

i think i'll just rephrase the array to add another field of countryName in it. i just like the way it make the view file much cleaner

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB