CI syntax debugging - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: CI syntax debugging (/showthread.php?tid=7109) |
CI syntax debugging - El Forum - 03-25-2008 [eluser]mohfeza code ignitor[/eluser] Please let me know how i can write the following line of code with loading config item-- foreach ($arModeSortType[$sCurrentMode] as $sModeSortType => $sDisplay) { I tried the following line of code, but it's not working- foreach ($this->config->item('arModeSortType[$this->config->item("sCurrentMode")]') as $sModeSortType => $sDisplay) { In autoloaded config file contains- $config['sCurrentMode'] = 'books'; // Sort Types $config['arModeSortType'] = array ( 'baby' => array( '+pmrank' => 'Featured Items', '+salesrank' => 'Bestselling', '+titlerank' => 'Alphabetical (A-Z)', ), 'books' => array( '+pmrank' => 'Featured Items', '+salesrank' => 'Bestselling', '+reviewrank' => 'Average Customer Review', '+pricerank' => 'Price (Low to High)', '+inverse-pricerank' => 'Price (High to Low)', '+daterank' => 'Publication Date', '+titlerank' => 'Alphabetical (A-Z)', '-titlerank' => 'Alphabetical (Z-A)', ), 'classical' => array( '+pmrank' => 'Featured Items', '+salesrank' => 'Bestselling', '+titlerank' => 'Alphabetical (A-Z)', ), 'dvd' => array( '+salesrank' => 'Bestselling', '+titlerank' => 'Alphabetical', ), 'electronics' => array( '+pmrank' => 'Featured Items', '+salesrank' => 'Bestselling', '+titlerank' => 'Alphabetical', '+reviewrank' => 'Review', ), 'garden' => array( '+psrank' => 'Featured Items', '+salesrank' => 'Bestselling', '+titlerank' => 'Alphabetical (A-Z)', '-titlerank' => 'Alphabetical (Z-A)', '+manufactrank' => 'Manufacturer (A-Z)', '-manufactrank' => 'Manufacturer (Z-A)', '+price' => 'Price (Low to High)', '-price' => 'Price (High to Low)', ), 'kitchen' => array( '+psrank' => 'Featured Items', '+salesrank' => 'Bestselling', '+titlerank' => 'Alphabetical (A-Z)', '-titlerank' => 'Alphabetical (Z-A)', '+manufactrank' => 'Manufacturer (A-Z)', '-manufactrank' => 'Manufacturer (Z-A)', '+price' => 'Price (Low to High)', '-price' => 'Price (High to Low)', ), 'magazines' => array( '+pmrank' => 'Featured Items', '+salesrank' => 'Bestselling', '+titlerank' => 'Alphabetical (A-Z)', ), 'music' => array( '+psrank' => 'Featured Items', '+salesrank' => 'Bestselling', '+artistrank' => 'Artist Name', '+orig-rel-date' => 'Original Release Date', '+titlerank' => 'Alphabetical', ), 'pc-hardware' => array( '+psrank' => 'Featured Items', '+salesrank' => 'Bestselling', '+titlerank' => 'Alphabetical (A-Z)', '-titlerank' => 'Alphabetical (Z-A)', ), 'photo' => array( '+pmrank' => 'Featured Items', '+salesrank' => 'Bestselling', '+titlerank' => 'Alphabetical (A-Z)', '-titlerank' => 'Alphabetical (Z-A)', ), 'software' => array( '+pmrank' => 'Featured Items', '+salesrank' => 'Bestselling', '+titlerank' => 'Alphabetical', '+price' => 'Price (Low to High)', '+price' => 'Price (High to Low)', ), 'toys' => array( '+pmrank' => 'Featured Items', '+salesrank' => 'Bestselling', '+titlerank' => 'Alphabetical (A-Z)', ), 'universal' => array( '+psrank' => 'Featured Items', '+salesrank' => 'Bestselling', '+titlerank' => 'Alphabetical (A-Z)', '-titlerank' => 'Alphabetical (Z-A)', '+manufactrank' => 'Manufacturer (A-Z)', '-manufactrank' => 'Manufacturer (Z-A)', '+price' => 'Price (Low to High)', '-price' => 'Price (High to Low)', ), 'vhs' => array( '+psrank' => 'Featured Items', '+salesrank' => 'Bestselling', '+titlerank' => 'Alphabetical', ), 'videogames' => array( '+pmrank' => 'Featured Items', '+salesrank' => 'Bestselling', '+titlerank' => 'Alphabetical', '+price' => 'Price (Low to High)', '-price' => 'Price (High to Low)', ), ); CI syntax debugging - El Forum - 03-25-2008 [eluser]gRoberts[/eluser] Code: foreach($this->config->item('arModeSortType')[$this->config->item('sCurrentMode')] as $sModeSortType => $sDisplay) { But it would be better to store these in a variable before using them in an foreach loop. CI syntax debugging - El Forum - 03-25-2008 [eluser]xwero[/eluser] Code: $this->config->item(’arModeSortType[$this->config->item("sCurrentMode")]’) Code: $this->config->item(’arModeSortType['.$this->config->item("sCurrentMode").']’) ps : could you use the bbcode code tags then the code is highlighted, a lot of people come to depend on highlighting to discover errors. CI syntax debugging - El Forum - 03-25-2008 [eluser]mohfeza code ignitor[/eluser] neither one is working. I also tried with variable. please help asap CI syntax debugging - El Forum - 03-25-2008 [eluser]gRoberts[/eluser] I've just noticed your expecting to use "sCurrentMode" as the index of an array. you need to change your array to : Code: $config['sCurrentMode'] = 'books'; CI syntax debugging - El Forum - 03-25-2008 [eluser]xwero[/eluser] gRoberts that is the same only your way is easier to read. Are you sure the output of Code: $this->config->item("sCurrentMode") have you checked the output of Code: $this->config->item(’arModeSortType["books"]’) Code: $current = 'books'; if that works and sCurrentMode outputs books you can try Code: $current = $this->config->item("sCurrentMode"); CI syntax debugging - El Forum - 03-25-2008 [eluser]gRoberts[/eluser] So it is, I didn't notice that. I thought that item() was to return the value of the config array with the given key/index. Are you sure you can provide `arModeSortType['books']` as an index, as I wouldn't expect item() to first get arModeSortType and then return the array at that key/index? Code: $types = $this->config->item('arModeSortType'); What does the above code output? |