ciao ragazzi,
cerco di essere sintetico, ho una classe ControlPanel, nella quale gestisco un certo numero di opzioni tutte nella vaiabile $options.
ecco il listato
Codice PHP:
<?php /*
class ControlPanel {
/* Array for Default Options */
var $default_settings = Array(
'option7' => '0',
);
var $options;
function ControlPanel() {
add_action('admin_menu', array(&$this, 'add_menu'));
add_action('admin_head', array(&$this, 'admin_head'));
if (!is_array(get_option('customoptions_panel')))
add_option('customoptions_panel', $this->default_settings);
$this->options = get_option('customoptions_panel');
}
function add_menu() {
add_theme_page('Options Panel', 'Options Panel', 8, "customoptions_panel", array(&$this, 'optionsmenu'));
}
function optionsmenu() {
if ($_POST['ss_action'] == 'save') {
$this->options["option7"] = $_POST['cp_option'];
update_option('customoptions_panel',$this->options);
echo '<div class="updated fade" id="message">Options have been saved</div>';
}
echo '<form action="" method="post" class="themeform">';
echo '<input type="hidden" id="ss_action" name="ss_action" value="save">';
print'<h4 class="fleft">Select Category for this BLOCK</h4>';
catlist("option7");
/*
This will:
1. generate a select list
2. the user will choose a category
3. the choice gets stored under $this->options['option7'] (which was 0 by default, and is now, let's say, 11, the "Movies" category)
The thing works and the categort gets stored, but then I am not able to retrieve this stored information.
I need it to assign selected="selected" to the currently used category.
So that, next time, I can see the "Movies" category as the chosen one, and not the first <option> element in the select list.
The panel would end up ovverwriting the user choice of the "Movies" category with the "Apple Computers" one, because it's the 1st in the list.
*/
echo '<input type="submit" value="Save" name="cp_save" class="dochanges" />';
echo '</form>';
}
}
// instance of the ControlPanel
$cpanel = new ControlPanel();
// the function that I used in the class
function catlist($target_option) {
$current_cat = $cpanel->$options[$target_option]; // in this example, shouldn't $target_option = option7 ???
$cat_obj = get_categories('hide_empty=0');
$cat = array();
print '<select name="'.$target_option.'" id="'.$target_option.'">';
foreach ($cat_obj as $cat) {
$cat_id = $cat->cat_ID;
$cat_name = $cat->cat_name;
echo '<option value="'.$cat_id.'"';
if ($current_cat == $cat_id) echo 'selected="selected"';
echo '>'.$cat_name.'</option>';
}
print '</select>';
}
?>
per far si che la funzione catlist (esterna alla classe) funzioni al 100%, avrei bisogno di accedere alla classe tramite istanza in questo modo:
$cpanel->$options[$target_option]
ma per qualche motivo questa cosa al momento non funziona.
premetto che sono alle prime armi in server-side, quindi potrei aver commesso qualche sciocchezza enorme
perche se all interno della classe
Codice PHP:
$this->options["option7"]
funziona, mentre al di fuori nonostante l'istanza sia stata creata
Codice PHP:
$cpanel->$options[$target_option]
invece non funziona?
Grazie in anticipo,
se avete anche buone letture in merito all argomento classi specifico, sono molto interessato.
Ho gia sfogliato quelle di html, non so se la risposta si celava li ma cerco ugualmente qualcosa di approfondito