Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Widocznosc/Dostepnosc wlasciwosci - wybiorczo, Wlasciwosc w klasie /
JakubBab
post
Post #1





Grupa: Zarejestrowani
Postów: 96
Pomógł: 2
Dołączył: 13.07.2015

Ostrzeżenie: (0%)
-----


Czesc,

Taka oto zagwozdka:

- przypisuje wlasciwosci wartosc w funkcji. Jest ona widoczna w innej klasie nastomiast w drugiej ma on wartosc null. Why?! Chodzi o -> protected $temp;

  1.  
  2.  
  3. .....
  4.  
  5. protected $temp;
  6. public function tableTh() {
  7.  
  8. for ($i = 0; $i <= 7; $i++) {
  9.  
  10. if ($i == 0) {
  11. $this->tableTh.='<td width="25px" style="background: #c0c0c0;">X</td>';
  12. } else if ($i == 1) {
  13. // -7 because it has to get the day commencing the week - monday
  14.  
  15. $this->tableTh .= '<td style="background: #c0c0c0;">' . $this->giveCalendarName() . "</br>" . $this->giveCalendarNumber('null',7) . '</td>';
  16. $this->temp= $this->giveCalendarNumber(7,$i-7);
  17.  
  18. } else if ($i > 1) {
  19. // -7 because it has to get the day commencing the week - monday
  20. $this->tableTh .= '<td style="background: #c0c0c0;">' . $this->giveCalendarName($i - 1) . "</br>" . $this->giveCalendarNumber(7,$i-1) . '</td>';
  21. $this->temp= $this->giveCalendarNumber(7,$i-7);
  22.  
  23. }
  24. }
  25.  
  26. return $this->tableTh;
  27. }


Tutaj (ponizej) ma rece i nogi i po wywolaniu dostaje wartosc taka jaka chce czyli - (w tym konkretnym przypadku) string 07.03.2016.

  1. public function tableRow() {
  2.  
  3.  
  4. for ($i = 1; $i <= 8; $i++) {
  5. echo "<tr></tr>";
  6.  
  7. for ($j = 0; $j <= 7; $j++) {
  8.  
  9. if ($j == 0) {
  10. echo '<td width="30px" style="background: #c0c0c0;">' . $this->giveTime(9 + $i - 1) . '</br></td>';
  11. } else {
  12.  
  13. echo '<td><input type="checkbox" name="Reservation[' . $j . ']['.$this->temp.'][' . $i . ']" value="1"></br></td>';
  14. }
  15. }
  16. }
  17.  
  18. }


Natomiast gdy chce uzyc tej samej wlasciwosci ($this->temp) w innej funkcji ma ona wartosc NULL. Jakies pomysly?

Ten post edytował JakubBab 9.03.2016, 22:24:09
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
JakubBab
post
Post #2





Grupa: Zarejestrowani
Postów: 96
Pomógł: 2
Dołączył: 13.07.2015

Ostrzeżenie: (0%)
-----


Cytat(Pyton_000 @ 10.03.2016, 08:07:22 ) *
To może pokaż kod który nie działa? Bo strasznie zamieszałeś.




Chodzi o $this->temp. W pierwszej funkcji przyjmuje on $this->giveCalendarNumber (ktory jest ekwiwalentem 7.03.2016) .RowTh() w ktorym znajduje sie $this->temp wyswietlam go <form> i dziala (czyli <form> wyswietla go jako string 7.03.2016). Jednak, gdy chce uzyc tej samej wlasciwosci ($this->temp) w innej ( w jakiejkolwiek) funkcji przyjmuje on wartosc NULL. Nie wiem dlaczego, ale obszedlem to tworzac inna funckje i przypisujac wartosc $this->giveCalendarNumber() do innej wlaciwosci.

W ramach przypomnienia: skad bierze sie $this->temp :

  1. protected $temp;
  2.  
  3. public function tableTh() {
  4.  
  5. for ($i = 0; $i <= 7; $i++) {
  6.  
  7. if ($i == 0) {
  8. $this->tableTh.='<td width="25px" style="background: #c0c0c0;">X</td>';
  9. } else if ($i == 1) {
  10. // -7 because it has to get the day commencing the week - monday
  11.  
  12. $this->tableTh .= '<td style="background: #c0c0c0;">' . $this->giveCalendarName() . "</br>" . $this->giveCalendarNumber(7,'null) . '</td>';
  13. $this->temp= $this->giveCalendarNumber(7,$i-7);
  14.  
  15. } else if ($i > 1) {
  16. // -7 because it has to get the day commencing the week - monday
  17. $this->tableTh .= '<td style="background: #c0c0c0;">' . $this->giveCalendarName($i - 1) . "</br>" . $this->giveCalendarNumber(7,$i-1) . '</td>';
  18. $this->temp= $this->giveCalendarNumber(7,$i-7);
  19.  
  20. }
  21. }
  22.  
  23. return $this->tableTh;
  24. }


Tutaj $this->temp dziala i wyswietla to co chce (7.03.2016).
  1. public function tableRow() {
  2.  
  3.  
  4. for ($i = 1; $i <= 8; $i++) {
  5. echo "<tr></tr>";
  6.  
  7. for ($j = 0; $j <= 7; $j++) {
  8.  
  9. if ($j == 0) {
  10. echo '<td width="30px" style="background: #c0c0c0;">' . $this->giveTime(9 + $i - 1) . '</br></td>';
  11. } else {
  12.  
  13. echo '<td><input type="checkbox" name="Reservation[' . $j . ']['.$this->temp.'][' . $i . ']" value="1"></br></td>';
  14. }
  15. }
  16. }
  17.  
  18. }




Przykladowa funkcja (w tej samej klasie ) ktorej to samo $this->temp zwraca wartosc null

  1. public function giveTemp(){
  2. $test = $this->temp;
  3. return $test;
  4. }
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 10.10.2025 - 13:29