我可能有一個非常簡單的問題,但我現在不知道如何解決它。也許我只是忘了一些東西,但我需要你的幫助。繼承變量不起作用
我有模式:
<?php
class Model
{
protected $storage;
public function __construct()
{
$this->storage = $_SERVER["DOCUMENT_ROOT"] . "/mvc/images/";
if(!file_exists($this->storage))
{
mkdir($this->storage, 0777);
}
}
public function storageHandler()
{
if(count(glob($this->storage."/*")) === 0)
{
echo "Žiadne kategórie";
}
else
{
$iterator = new DirectoryIterator($this->storage);
return $iterator;
}
}
}
?>
和型號類別,這是從模型繼承。
<?php
require_once($_SERVER["DOCUMENT_ROOT"] . "/mvc/model/Model.php");
class Category extends Model
{
private $photos_count;
public function __construct($data)
{
if(isset($data))
{
$gallery_path = $this->storage . $data;
if(!file_exists($this->$storage .$data))
{
mkdir($tihs->storage . $data, 0700);
header("Location: /mvc/");
}
else
{
echo "Kategória už existuje.";
}
}
}
}
?>
我希望在我的Category類中使用Model中的$ storage變量。我應該怎麼做?我知道某種方式,但它不會是最好的。有什麼解決方案可以做出這種好的方式嗎?
比錯字其他,這有什麼錯你這樣做的方式嗎? – Barmar