Welcome Guest, Not a member yet? Register   Sign In
CI syntax debugging
#1

[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)',
),
);
#2

[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.
#3

[eluser]xwero[/eluser]
Code:
$this->config->item(’arModeSortType[$this->config->item("sCurrentMode")]’)
should be changed to
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.
#4

[eluser]mohfeza code ignitor[/eluser]
neither one is working. I also tried with variable. please help asap
#5

[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';

// Sort Types
$config['arModeSortType']['baby'] = array (
    '+pmrank' => 'Featured Items',
    '+salesrank' => 'Bestselling',
    '+titlerank' => 'Alphabetical (A-Z)',
);

$config['arModeSortType']['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)',
);
$config['arModeSortType']['classical'] = array (
    '+pmrank' => 'Featured Items',
    '+salesrank' => 'Bestselling',
    '+titlerank' => 'Alphabetical (A-Z)',
);
$config['arModeSortType']['dvd'] = array (
    '+salesrank' => 'Bestselling',
    '+titlerank' => 'Alphabetical',
);
$config['arModeSortType']['electronics'] = array (
    '+pmrank' => 'Featured Items',
    '+salesrank' => 'Bestselling',
    '+titlerank' => 'Alphabetical',
    '+reviewrank' => 'Review',
);
$config['arModeSortType']['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)',
);
$config['arModeSortType']['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)',
);
$config['arModeSortType']['magazines'] = array (
    '+pmrank' => 'Featured Items',
    '+salesrank' => 'Bestselling',
    '+titlerank' => 'Alphabetical (A-Z)',
);
$config['arModeSortType']['music'] = array (
    '+psrank' => 'Featured Items',
    '+salesrank' => 'Bestselling',
    '+artistrank' => 'Artist Name',
    '+orig-rel-date' => 'Original Release Date',
    '+titlerank' => 'Alphabetical',
);
$config['arModeSortType']['pc-hardware'] = array (
    '+psrank' => 'Featured Items',
    '+salesrank' => 'Bestselling',
    '+titlerank' => 'Alphabetical (A-Z)',
    '-titlerank' => 'Alphabetical (Z-A)',
);
$config['arModeSortType']['photo'] = array (
    '+pmrank' => 'Featured Items',
    '+salesrank' => 'Bestselling',
    '+titlerank' => 'Alphabetical (A-Z)',
    '-titlerank' => 'Alphabetical (Z-A)',
);
$config['arModeSortType']['software'] = array (
    '+pmrank' => 'Featured Items',
    '+salesrank' => 'Bestselling',
    '+titlerank' => 'Alphabetical',
    '+price' => 'Price (Low to High)',
    '+price' => 'Price (High to Low)',
);
$config['arModeSortType']['toys'] = array (
    '+pmrank' => 'Featured Items',
    '+salesrank' => 'Bestselling',
    '+titlerank' => 'Alphabetical (A-Z)',
);
$config['arModeSortType']['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)',
);
$config['arModeSortType']['vhs'] = array (
    '+psrank' => 'Featured Items',
    '+salesrank' => 'Bestselling',
    '+titlerank' => 'Alphabetical',
);
$config['arModeSortType']['videogames'] = array (
    '+pmrank' => 'Featured Items',
    '+salesrank' => 'Bestselling',
    '+titlerank' => 'Alphabetical',
    '+price' => 'Price (Low to High)',
    '-price' => 'Price (High to Low)',
);
#6

[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")
is books? I find it strange you use a config value to determine which array you need to get.

have you checked the output of
Code:
$this->config->item(’arModeSortType["books"]’)
If you get the right array you can try
Code:
$current = 'books';
$this->config->item(’arModeSortType['.$current.']’)

if that works and sCurrentMode outputs books you can try
Code:
$current = $this->config->item("sCurrentMode");
$this->config->item(’arModeSortType['.$current.']’)
#7

[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');
$current = $this->config->item('sCurrentMode');
echo "Types: <pre>";
print_r($types);
echo "</pre><br />Current:<pre>";
print_r($current);
echo "</pre><br />Current Data:<pre>";
print_r($types[$current]);
echo "</pre>";

What does the above code output?




Theme © iAndrew 2016 - Forum software by © MyBB