我是 OOP 的新手并且有一个课程,在这个课程中我正在尝试运行
foreach($categories as $category) {
public function beam_channels_setting.$category->name()
{
echo "<input name='beam_plugin_options[beam_channels".$category->name"]' type='text' value='{$this->options['beam_channels.$category->name']}'/>";
}
}
但是我不断收到此错误:意外的 T_FOREACH
我知道这是因为它正在寻找一个函数,但我不知道如何克服这个问题,我会把它全部放在另一个函数中吗?
班级
Class BEAM_Options {
public $options;
public $categorielist;
public function __construct()
{
$args = array(
'type' => 'post',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0, //<--IMPORTANT!!
'hierarchical' => 1,
'taxonomy' => 'category',
'pad_counts' => false );
$categories = get_categories($args);
$this->options = get_option('beam_plugin_options');
$this->register_settings_and_fields();
}
public function add_menu_page()
{
add_options_page('Ad Management', 'Ad Management', 'administrator', __FILE__, array('BEAM_Options', 'display_options_page'));
}
public function display_options_page()
{
?>
<div class="wrap">
<?php screen_icon(); ?>
<h2> Ad Management</h2>
<form method="post" action="options.php">
<?php settings_fields('beam_plugin_options'); ?>
<?php do_settings_sections(__FILE__); ?>
<p class="submit">
<input name="submit" type="submit" class="button-primary" value="Save Changes" />
</p>
</form>
</div>
<?php
}
public function register_settings_and_fields()
{
register_setting('beam_plugin_options', 'beam_plugin_options');
add_settings_section('beam_main_section', 'Settings', array($this, 'beam_main_section_cb'), __FILE__); //id, title, section, callback, page
add_settings_field('beam_refresh_time_truth','Do you want the Advertisements to Auto-Refresh?', array($this,'beam_refresh_time_truth_setting'), __FILE__, 'beam_main_section');
add_settings_field('beam_refresh_time','Refresh Time(seconds)', array($this,'beam_refresh_time_setting'), __FILE__, 'beam_main_section');
$args = array(
'type' => 'post',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0, //<--IMPORTANT!!
'hierarchical' => 1,
'taxonomy' => 'category',
'pad_counts' => false );
$categories = get_categories($args);
foreach($categories as $category) {
add_settings_field("beam_channels.$category->name","$category->name", array($this,"beam_channels_setting.$category->name"), __FILE__, 'beam_main_section');
}
}
foreach($categories as $category) {
public function beam_channels_setting.$category->name()
{
echo "<input name='beam_plugin_options[beam_channels".$category->name"]' type='text' value='{$this->options['beam_channels.$category->name']}'/>";
}
}
}