【发布时间】:2016-07-02 08:14:24
【问题描述】:
这里是开拓者。我正在自学php和sql。目前我正在开发一个应用程序并使用此教程视频作为模板:
https://youtu.be/tPspjWX8GXw?t=15m24s
为了节省时间,我从遇到问题的地方开始。 I've included an image stating the issue in question. 目前我正在努力解决它,但我对 PHP 的了解还不够,还不知道如何解决它。有问题的行(在我完成此操作时可能是行)是:
$serialArray = $serialModelCode->GetSerialByName($name);
根据我的理解,我应该创建一个名为“serialArray”的变量,并将其传递给一个新对象(serialModelCode)。然后这应该传递给另一个文件的参数:GetSerialByName($name);
但是似乎没有任何工作正常。下面我已经包含了我的所有代码。如果有人可以帮助我弄清楚我的问题并了解发生了什么,那将不胜感激。另外,如果我上面的逻辑有缺陷,请告诉我。
-
开拓者
需要(“型号/SerialModel.php”); 类串行控制器 {
函数 CreateSerialDropdownList()
{ $serialModelCode = new $SerialModel();
/* * Creates a drop down list * Takes the Serial Types and puts them into an array */ $result = "<form action = '' method = 'post' width = '200px'> Please select an Item: <select name = 'names' > <option value = '%' >All</option> " . $this->CreateOptionValues($serialModelCode->GetSerialNames()) . "</select> <input type = 'submit' value = 'Search' /> </form>"; return $result;} 函数 CreateOptionValues(数组 $valueArray) { $结果 = "";
foreach ($valueArray as $value) { $result = $result . "<option value='$value'>$value</option>"; } return $result;} 函数 CreateSerialTables ($names) {
$serialModelCode = new $SerialModel(); $serialArray = $serialModelCode->GetSerialByName($name); $result = ""; /* * Generates a serialTable for each Serial Entity in the array */ foreach ($serialArray as $key => $serial) { $result = $result . /* * Will need to change coffeeTable to serialTable * at some point. Not right now though */ "<table class = 'coffeeTable'> <tr> <th rowspan='6' width = '150px' ><img runat = 'server' src = '$serial->image' /></th> <th width = '75px' >Name: </th> <td>$serial->name</td> </tr> <tr> <th>Type: </th> <td>$serial->type</td> </tr> <tr> <th>Price: </th> <td>$serial->price</td> </tr> <tr> <th>Serial Number: </th> <td>$serial->serialNum</td> </tr> <tr> <td colspan='2' >$coffee->desc</td> </tr> </table>"; } return $result;}}?>
编辑:显然我的格式有问题。哎哟。我已经修复了很多,但是有些空间不想正常配合。
【问题讨论】:
标签: php class variables object undefined