我的IDE正在显示"解析错误"在我的php文件的这一行:
var $ meat = new Category(无肉,1);
我试图让这行代码工作:
return parent::displayData($viewData);
$ViewData
需要是Category
个对象的数组。
我的语法在哪里绊倒我?
以下是完整档案:
class CategorySelect extends BaseSelect {
static $template = 'select_multiple_template.php';
public static function display() {
var $meat = new Category(Meat-Free Meat, 1);
var $dairy = new Category(Dairy-Free dairy, 2);
var $confectionery = new Category(Confectionery, 3);
var $baking = new Category(Baking, 4);
var $dessert = new Category(Dessert, 5);
var $viewData = array($meat, $dairy, $confectionery, $baking, $dessert);
return parent::displayData($viewData);
}
}
class Category {
function Category($name, $id) {
$this->name = $name;
$this->id = $id;
}
}
这是它正在扩展的抽象类:
interface iSelect {
public static function display();
}
abstract class BaseSelect implements iSelect {
static $template = 'select_template.php';
public static function displayData($viewData) {
if ( class_exists( 'View' ) ) {
$templatePath = dirname( __FILE__ ) . '/' . static::$template;
return View::render( $templatePath, $viewData );
}
else {
return "You are trying to render a template, but we can't find the View Class";
}
}
}
答案 0 :(得分:8)
你的问题在这里
var $meat = new Category(Meat-Free Meat, 1);
var $dairy = new Category(Dairy-Free dairy, 2);
无肉肉是正确的吗?你必须添加引号,然后它应该是:
$meat = new Category("Meat-Free Meat", 1);
$dairy = new Category("Dairy-Free dairy", 2);