Здравствуйте!
Я только учусь,тапками сильно не кидайте,поиск юзал,туторы читал,все равно не понял.
В общем мне нужно написать класс который будет дописывать информацию в php файл.
И если входящей информации нет, то записать из предопределенных св-в класса.
Написал вот это, но не пойму как исправить ошибки.
CODE ( htmlphp):
скопировать код в буфер обмена
<?php include ('FileCreateClass.php'); class WriteIndexArticle { protected $Article = 'Пустая страница'; protected $ArticleIndexFile = 'IndexArticleFile.php'; protected $ArticleIndexPrefix = 'Article'; protected $IndexFile = '<?php $Article = Array; ?>'; function __construct($Article,$ArticleIndexFile,$ArticleIndexPrefix){ $this->Article = $Article ; $this->ArticleIndexFile = $ArticleIndexFile ; $this->ArticleIndexPrefix = $ArticleIndexPrefix ; $this->IndexFile = '<?php $'.$this->ArticleIndexPrefix.'[] = "'.$this->Article.'"; ?>'; } //класс просто записывает в файл function WriteArticle(){ $Write = new FileCreate($this->ArticleIndexFile,$this->IndexFile,'a'); $Write -> Create(); } } echo '<form method="POST" action="section.php">'; echo 'Статья:<textarea name="Article" cols="15" rows="5" value=""></textarea></br>'; echo '<input type="submit" name="submit" value="добавить"></form>'; If(isset($_POST['submit'])){ $Create = new WriteIndexArticle($_POST['Article']); $Create -> WriteArticle(); } ?>
FileCreateClass.php (Отобразить)CODE ( htmlphp):
скопировать код в буфер обмена
<?php class FileCreate{ protected $SectionFName = "index.php"; protected $SectionContent = "<?php ?>"; private $AccesMod = "w"; function __construct($SectionFName,$SectionContent,$AccesMod){ $this->SectionFName = $SectionFName; $this->SectionContent = $SectionContent; $this->AccesMod = $AccesMod; } function Create(){ $f = fopen ($this->SectionFName,$this->AccesMod); fwrite ($f,$this->SectionContent); fclose ($f); } } ?>
Ошибки (Отобразить)Warning: Missing argument 2 for WriteIndexArticle::__construct(), called in W:\html\gtemp.php\www\section.php on line 71 and defined in W:\html\gtemp.php\www\section.php on line 50
Warning: Missing argument 3 for WriteIndexArticle::__construct(), called in W:\html\gtemp.php\www\section.php on line 71 and defined in W:\html\gtemp.php\www\section.php on line 50
Notice: Undefined variable: ArticleIndexFile in W:\html\gtemp.php\www\section.php on line 52
Notice: Undefined variable: ArticleIndexPrefix in W:\html\gtemp.php\www\section.php on line 53
Warning: fopen() [function.fopen]: Filename cannot be empty in W:\html\gtemp.php\www\FileCreateClass.php on line 14
Warning: fwrite(): supplied argument is not a valid stream resource in W:\html\gtemp.php\www\FileCreateClass.php on line 15
Warning: fclose(): supplied argument is not a valid stream resource in W:\html\gtemp.php\www\FileCreateClass.php on line 16
В общем,я то ли принцип конструкторов неправильно понимаю, то ли просто синтаксис неправильный. Помогите пожалуйста разобраться.
|