我刚开始使用php,为我的大学做一个网站,但由于某些原因我无法让我的构造函数工作。
User.class.php
class User {
public $id="";
public $name="";
public $vorname="";
public $matrikelnummer="";
public $status="";
public $wl_platz="";
public $modul="";
public $versuch="";
public function __construct($id, $name, $vorname, $matrikelnummer, $status, $wl_platz, $modul, $versuch)
{
$this->$id=$id;
$this->$name=$name;
$this->$vorname=$vorname;
$this->$matrikelnummer=$matrikelnummer;
$this->$status=$status;
$this->$wl_platz=$wl_platz;
$this->$modul=$modul;
$this->$versuch=$versuch;
}
在main.php中
include_once('include/User.class.php');
$user=new User($id, $name, $vorname, $mn, $status, $wl_platz, $modul, $versuch);
调用中的变量是之前设置的字符串,显然是
如果我做echo serialize($ user);
我得到了
O:4:"User":16:{s:2:"id";s:0:"";s:4:"name";s:0:"";s:7:"vorname";s:0:"";
s:14:"matrikelnummer";s:0:"";s:6:"status";s:0:"";s:8:"wl_platz";
s:0:"";s:5:"modul";s:0:"";s:7:"versuch";s:0:"";s:1:"1";s:1:"1";s:9:
"alexander";s:9:"alexander";s:4:"jung";s:4:"jung";s:5:"34525";s:5:"34525"
;s:19:"registered for exam";s:19:"registered for exam";
s:4:"TODO";s:4:"TODO";s:3:"PAD";s:3:"PAD";s:1:"3";s:1:"3";}
所以它只是某种工作,但如果我回复$ user-> name; 我得到空输出。 非常肯定某处肯定会有一个小错误,但找不到它......(我做了一些搜索和所有)
答案 0 :(得分:2)
您没有按 new Vue({
el : '#myapp',
data : {
type : 'none',
category : {
count : '{{ $categories->count() }}',
error : false,
selected : 0,
validation: false,
show : true,
},
event : {
count : '{{ $events->count() }}',
error : false,
selected : 0,
validation: false,
show : true,
},
error : false,
discount : false,
coordinates : [],
slides : [],
categories : {!! $categories->toJson() !!},
features : {!! $features->toJson() !!},
selected_features : [],
selected_categories: [],
},
mounted: function () {
this.features.map(function (value, key) {
Object.assign(value, {
color : 'dark',
selected_conditions: [],
})
});
this.categories.map(function (value, key) {
Object.assign(value, {
color : 'dark',
chosen_features: [],
})
});
},
updated: function () {
switch (this.type) {
case('category'):
this.event.error = false;
if (this.category.count < 1) {
this.category.error = true;
this.error = true;
} else {
this.error = false;
}
break;
case('event'):
this.category.error = false;
if (this.event.count < 1) {
this.event.error = true;
this.error = true;
}
else {
this.error = false;
}
break;
}
},
methods: {
addCoordinate: function () {
if (this.coordinates.length === 0) {
this.coordinates.push({
id: this.coordinates.length + 1,
})
} else {
this.coordinates.push({
id: this.coordinates[this.coordinates.length - 1].id + 1,
})
}
},
removeCoordinate: function (coordinate) {
this.coordinates.splice(this.coordinates.indexOf(coordinate), 1)
},
addSlide: function () {
if (this.slides.length === 0) {
this.slides.push({
id : this.slides.length + 1,
show_image: false,
})
} else {
this.slides.push({
id : this.slides[this.slides.length - 1].id + 1,
show_image: false,
})
}
},
removeSlide: function (slide) {
this.slides.splice(this.slides.indexOf(slide), 1)
},
readURL: function (slide) {
console.log(slide);
var input = $('#slide-' + slide.id)[0]
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
slide.show_image = true;
$('#slide-image-' + slide.id).attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
},
addFeature: function (feature) {
data = {
id : feature.id,
label : feature.label,
title : feature.title,
description : feature.description,
conditions : feature.conditions,
selected_conditions: [],
}
if (this.selected_features.length > 0) {
if (search(data.id, this.selected_features) === undefined) {
this.selected_features.push(data)
Object.assign(feature, {
color: 'success',
})
} else {
Object.assign(search(feature.id, this.features), {
color: 'dark',
})
this.selected_features.splice(this.selected_features.indexOf(feature), 1)
}
} else {
this.selected_features.push(data)
Object.assign(feature, {
color: 'success',
})
}
},
removeFeature: function (feature) {
Object.assign(search(feature.id, this.features), {
color: 'dark',
})
this.selected_features.splice(this.selected_features.indexOf(feature), 1)
},
addCategory: function (category) {
data = {
id : category.id,
title : category.title,
description : category.description,
chosen_features: [],
}
if (this.selected_categories.length > 0) {
if (search(data.id, this.selected_categories) === undefined) {
this.selected_categories.push(data)
Object.assign(category, {
color: 'success',
})
} else {
Object.assign(search(category.id, this.categories), {
color: 'dark',
})
this.selected_categories.splice(this.selected_categories.indexOf(category), 1)
}
} else {
this.selected_categories.push(data)
Object.assign(category, {
color: 'success',
})
}
},
removeCategory: function (category) {
Object.assign(search(category.id, this.categories), {
color: 'dark',
})
this.selected_categories.splice(this.selected_categories.indexOf(category), 1)
},
addConditionToChosenFeature: function (condition, feature, category) {
search(feature.id, category.chosen_features).selected_conditions.push(condition)
console.log(search(feature.id, category.chosen_features).selected_conditions);
},
Discounting: function () {
console.log('Changed')
if ($('#discount-button').is(":checked")) {
this.discount = true
} else {
this.discount = false
}
},
Searching: function (nameKey, myArray) {
for (var i = 0; i < myArray.length; i++) {
if (myArray[i].id === parseInt(nameKey)) {
return myArray[i];
}
}
}
},
});
设置属性。
就像你正在设置$this->$id
改变这个:
$this->yourvalueunder$id = ...
对此:
public function __construct($id, $name, $vorname, $matrikelnummer,
$status, $wl_platz, $modul, $versuch)
{
$this->$id=$id;
$this->$name=$name;
$this->$vorname=$vorname;
$this->$matrikelnummer=$matrikelnummer;
$this->$status=$status;
$this->$wl_platz=$wl_platz;
$this->$modul=$modul;
$this->$versuch=$versuch;
}