Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] Undefined offset: 1
Forum PHP.pl > Forum > Przedszkole
nygus9928
  1.  
  2. class Template {
  3. public $temp;
  4.  
  5. public $stemp;
  6.  
  7. public $track;
  8.  
  9. public $optype;
  10.  
  11. public $arr_elem;
  12.  
  13. public $temp_elem;
  14.  
  15. public $path = "templates/";
  16.  
  17. public $temp_name = "default";
  18.  
  19. public $ext = ".tpl";
  20.  
  21. public $arr_type = array("options","inputs");
  22.  
  23. public function render_page($tpl, $arr_data="", $directory="")
  24. {
  25. global $scms;
  26.  
  27. $directory = ($directory)? $directory."/" : $directory;
  28. $this->track = $this->path.$this->temp_name."/".$directory.$tpl.$this->ext;
  29. @$this->temp = file_get_contents($this->track);
  30.  
  31. if(empty($arr_data))
  32. return $this->temp;
  33.  
  34. if($this->temp)
  35. {
  36. foreach($arr_data as $elem => $val)
  37. {
  38. if(is_array($val))
  39. {
  40. $this->arr_elem = explode("-",$elem);
  41. $elem = $this->arr_elem[0];
  42. $this->temp_elem = substr($this->arr_elem[1], 0, -1);
  43. foreach($val as $attr => $op)
  44. {
  45. if(in_array($this->arr_elem[1] ,$this->arr_type))
  46. {
  47. switch($this->arr_elem[1])
  48. {
  49. case "options":
  50. $this->optype .= "<$this->temp_elem value=\"$attr\">$op</$this->temp_elem>";
  51. break;
  52.  
  53. case "inputs":
  54. $this->optype .= "$op<$this->temp_elem name=\"$attr\" />";
  55. break;
  56. }
  57. }
  58. else
  59. $this->optype .= $op;
  60. }
  61. $this->stemp = $this->optype;
  62. unset($this->optype);
  63. }
  64. else
  65. $this->stemp = $val;
  66.  
  67. $this->temp = str_replace("{tpl::$elem}", $this->stemp, $this->temp);
  68. }
  69.  
  70. $this->temp = preg_replace("({(.*?)})", "", $this->temp);
  71.  
  72. return $this->temp;
  73. }
  74. else
  75. return $this->track." not found<br />";
  76. }
  77.  
  78. public function __desctruct()
  79. {
  80. unset($this->temp);
  81. unset($this->stemp);
  82. unset($this->track);
  83. unset($this->arr_elem);
  84. unset($this->temp_elem);
  85. }


Wywala mi 1 błąd w 42 linijce i 6 błędów w 45.
Nie mam pojęcia co jest nie tak.
kpt_lucek
Pokaż przykładowy $elem

albo lepiej,

  1. function render_page($tpl, $arr_data = "", $directory = "") {
  2. global $scms;
  3.  
  4. $directory = ($directory) ? $directory . "/" : $directory;
  5. $this->track = $this->path . $this->temp_name . "/" . $directory . $tpl . $this->ext;
  6. @$this->temp = file_get_contents($this->track);
  7.  
  8. if (empty($arr_data))
  9. return $this->temp;
  10.  
  11. if ($this->temp) {
  12. foreach ($arr_data as $elem => $val) {
  13. if (is_array($val)) {
  14. print_r($elem);
  15. }
  16. }
  17. die;
  18. } else
  19. return $this->track . " not found<br />";
  20. }
nygus9928
  1. 60. "site_slogan" => $scms->settings['site_slogan'],
  2. 61. "welcome_message" => ($scms->session['loggedin'])? $txt['user']['24']. " <a href=\"#\">".$scms->session['user']."</a>" : $txt['user']['27'],
  3. 62 ."players_online" => ($online)? $online : 0,


Notice: Undefined index: loggedin in C:\xampp\htdocs\1\inc\functions.php on line 61
wywala mi całkiem strone
nospor
Cytat
Nie mam pojęcia co jest nie tak.
Toz wyraźnie ci napisalo, że dobierasz sie do inedksu 1, ktory nie istnieje.
w 42 i w 45 masz:
$this->temp_elem = substr($this->arr_elem[1], 0, -1);
if(in_array($this->arr_elem[1] ,$this->arr_type))

No i wszystko sie zgadza, bo w tych wlasnie linijkach dobierasz sie do indeksu 1. Komunikat bledu wyraźnie ci mowi, ze taki index nie istnieje. Czego nie rozumiesz?
nygus9928
Cytat(nospor @ 24.10.2014, 21:23:42 ) *
Toz wyraźnie ci napisalo, że dobierasz sie do inedksu 1, ktory nie istnieje.
w 42 i w 45 masz:
$this->temp_elem = substr($this->arr_elem[1], 0, -1);
if(in_array($this->arr_elem[1] ,$this->arr_type))

No i wszystko sie zgadza, bo w tych wlasnie linijkach dobierasz sie do indeksu 1. Komunikat bledu wyraźnie ci mowi, ze taki index nie istnieje. Czego nie rozumiesz?


Ok. Nie sprecyzowałem. Widzę błąd i co oznacza. Pytanie co powinno być tym elementem. To kawałek kodu z control panelu.
nospor
Tu:
$this->arr_elem = explode("-",$elem);
tworzysz tę nieszczesną tablice. Widac czasami, elem nie zawiera - przez co tworzy się tylko jeden element o indeksie 0. Nie wiem czy to prawidlowe czy nie, ze brak tam -. To twoj panel i powinienies to wiedziec a nie ja.
Jesli to prawidlowe, ze nie ma tam -, to poprostu zanim zaczniesz leciec do elementu 1, sprawdzaj czy taki istnieje.
Jesli to nie prawidlowe, ze nie ma tam -, to szuka bledu gdzies tam...
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.