更新:我得到这个PHP的错误:试图让该行非对象的属性: 如果($卡 - >名== $ fileRef){PHP构造函数单PARAM
我使用__construct(x='') { definition }
构建一个对象并调用函数$var = new Object('string');
构造函数接收一个字符串,即与相应的'file.php'相关的'文件'。在json文件中有这个类的所有可用file.php的目录,其中包含目录信息。
而我正在捕捉一个错误,也许与我的语法? ...现在让我有两天,想要摆动?
public function __construct($ctitle = '')
{
$fileRef = $ctitle.'php';
//Get the json card directory
$this->cardDirLocation = 'thisismyserver.com/CardDir.json';
$this->cardDir = file_get_contents($this->cardDirLocation);
$this->cardArray = json_decode($this->cardDir, true);
//Find the card listing from CardDir.json based on form response input and construct a Card class instance or use the main page (default)
foreach ($this->cardArray['Cards'] as $key => $val) { //search through each card IS THIS MY ERR??
if ($card->name == $fileRef){ //if the name matches a name in the cardDir.json file
//Fill Values
}
if ($this->title == ''){ //or if there is no title
$this->title = 'Get Started at The Home Page'; //refer to default values -> the home page
$this->dir = 'cards/start/';
$this->name = 'start.php'; ...etc
的错误:我不能得到$ fileRef变量与JSON文件阵列中的任何东西搭配起来,所以它总是进入“否则,如果”默认。 JSON文件看起来是这样的:
{"Cards":[{"title":"Something", "name":"file.php", "dir":"somefile/dir/here/" }, {"title":"Different than something", "name":"xfiles.php", "dir":"somefile/dir/there/" ...etc
什么是输出行'echo:$ val ['name']'? – 2013-05-14 17:28:48
谢谢这已被回答。 – 2013-05-14 18:14:15