[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: код на php
Страницы: 1, 2
k.shevchenko94
Здравствуйте, уважаемые пользователи форума. У меня проблемы с кодом программы. Кто может помогите пожалуйста. В моем классе есть метод returnId() - он должен прибавлять на единицу число и возвращать его. А ниже этот метод должен вернуть число на единицу и установить как значение атрибута id. Он устанавливает, но не увеличивает число. В чем ошибка ? Помогите. Пожалуйста.
Вот код.
<?php
class
UsersXML{
protected $_dom;
function __construct(){
if(!file_exists("users.xml")){
$this->_dom = new DomDocument("1.0","utf-8");
$this->_dom->formatOutput = true;
$this->_dom->preserveWhiteSpace = false;
$this->users = $this->_dom->createElement("users");
$this->_dom->appendChild($this->users);
$this->_dom->save("users.xml");
}else{
$this->_dom = new DomDocument("1.0","utf-8");
$this->_dom->formatOutput = true;
$this->_dom->preserveWhiteSpace = false;
$this->_dom->load("users.xml");
}
}

function __destruct(){
unset($this->_dom);
}
protected function returnId(){
static $id;
$id++;
return $id;
}
public function setItem($name,$email,$titleWork,$typeWork,$comment,$file){
$this->roof = $this->_dom->documentElement;
$user = $this->_dom->createElement('user');
$this->roof->appendChild($user);
$email = $this->_dom->createElement("email","$email");
$user->appendChild($email);
$user->setAttribute("id",$this->returnId());
$titleWork = $this->_dom->createElement("titlework","$titleWork");
$user->appendChild($titleWork);
$typeWork = $this->_dom->createElement("typework","$typeWork");
$user->appendChild($typeWork);
if($name){
$name = $this->_dom->createElement("name","$name");
$user->appendChild($name);
}else{
$name = $this->_dom->createElement("name","Нет имени");
$user->appendChild($name);}
if($comment){
$comment = $this->_dom->createElement("comment","$comment");
$user->appendChild($comment);
}else{
$comment = $this->_dom->createElement("comment","Нет комментария");
$user->appendChild($comment); }
if($file){
$file = $this->_dom->createElement("file","$file");
$user->appendChild($file);
$this->loadFile($file);
}else{
$file = $this->_dom->createElement("file","Нет файла");
$user->appendChild($file);}
$this->_dom->save("users.xml");
}
public function getItem(){
$this->users = $this->_dom->documentElement;
$this->user = $this->users->childNodes;
$this->userArray = array();
$this->userArrayItems = array();
foreach($this->user as $this->u){
if($this->u->nodeType == 1){
foreach($this->u->childNodes as $this->item){
if($this->item->nodeType == 1){
$this->userArrayItems[$this->item->tagName] = $this->item->nodeValue;
}
}

$this->userArray[] = $this->userArrayItems;
}
}

return $this->userArray;
}
public function deleteItem(){

}

protected function loadFile($file){
if($_FILES["file"]["error"] == 0){
$tmp_file = $_FILES["file"]["tmp_name"];
$file = $_FILES["file"]["name"];
move_uploaded_file($tmp_file,$file);
}

}

protected function clearData(){

}
}

?>
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.