Reputation: 12433
My IDE is showing "parse error" on this line of my php file:
var $meat = new Category(Meat-Free Meat, 1);
I'm trying to make this line of code work:
return parent::displayData($viewData);
And $ViewData
needs to be an array of Category
objects.
Where is my syntax tripping me up?
Here is the full file:
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;
}
}
Here is the abstract class it is extending:
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";
}
}
}
Upvotes: 3
Views: 82
Reputation: 2595
Your problem is here
var $meat = new Category(Meat-Free Meat, 1);
var $dairy = new Category(Dairy-Free dairy, 2);
Meat-Free Meat is as string right? you have to add quotes, then its should be:
$meat = new Category("Meat-Free Meat", 1);
$dairy = new Category("Dairy-Free dairy", 2);
Upvotes: 8