Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Problem z błędem typu notice
codeszan
post
Post #1





Grupa: Zarejestrowani
Postów: 61
Pomógł: 0
Dołączył: 2.07.2017

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


Mam formularz wyswietlajacy blad po wpisaniu emaila, blad w nim polegał(cz. przesz) na tym, iż po wyslaniu pustego formularza dostajesz zwrotny komunikat z sessi flashback, nastepnie klik w menu i sesja jeszcze nie ginie. Dopiero po kolejnym kliknieciu...

  1. if ($this->form_validation->run() == FALSE) {
  2. //nie stworzone konto
  3. $this->session->set_flashdata('item', array('message' => strip_tags(validation_errors()), 'class' => 'danger'));
  4. $this->twig->addGlobal('session', $this->session);
  5. $this->twig->display('admin/index');
  6.  
  7.  
  8. } else {
  9. $this->Model_User->create_users();
  10. $this->twig->addGlobal("session", $this->session);
  11. $this->twig->display('admin/index');
  12. }


Problem chciałem rozwiązać i w sumie rozwiazalem tym ze po warunkach z ifa dalem linijke ktora czysci sesje:
  1. $this->session->unset_userdata('item');


W tym momencie efekt jest ok efekt byłby dobry gdyby nie to, że po wyświetleniu komunikatu i powtórne wejściu w menu jest komunikat:

Cytat
A PHP Error was encountered
Severity: Notice

Message: Undefined index: item

Filename: Session/Session.php

Line Number: 879

Backtrace:

File: C:\xampp\htdocs\testowy\vendor\twig\twig\lib\Twig\Template.php
Line: 675
Function: flashdata

File: C:\xampp\htdocs\testowy\application\cache\twig\7e\7eb925d8470d4f00f6b4a2e674e68257d3507f8e89ce8dc18881811a2380d068.php
Line: 27
Function: getAttribute

File: C:\xampp\htdocs\testowy\vendor\twig\twig\lib\Twig\Template.php
Line: 432
Function: doDisplay

File: C:\xampp\htdocs\testowy\vendor\twig\twig\lib\Twig\Template.php
Line: 403
Function: displayWithErrorHandling

File: C:\xampp\htdocs\testowy\application\cache\twig\82\828dd2f6e47ff62e7aea02e48d9e693761611a8d1d52b3b199ae18ca4a733b88.php
Line: 42
Function: display

File: C:\xampp\htdocs\testowy\vendor\twig\twig\lib\Twig\Template.php
Line: 215
Function: block_body

File: C:\xampp\htdocs\testowy\application\cache\twig\c3\c32b30a36e75ee662ba512138737dbe4746c40306f080cd8b6f24bb2b016cd20.php
Line: 46
Function: displayBlock

File: C:\xampp\htdocs\testowy\vendor\twig\twig\lib\Twig\Template.php
Line: 432
Function: doDisplay

File: C:\xampp\htdocs\testowy\vendor\twig\twig\lib\Twig\Template.php
Line: 403
Function: displayWithErrorHandling

File: C:\xampp\htdocs\testowy\application\cache\twig\82\828dd2f6e47ff62e7aea02e48d9e693761611a8d1d52b3b199ae18ca4a733b88.php
Line: 24
Function: display

File: C:\xampp\htdocs\testowy\vendor\twig\twig\lib\Twig\Template.php
Line: 432
Function: doDisplay

File: C:\xampp\htdocs\testowy\vendor\twig\twig\lib\Twig\Template.php
Line: 403
Function: displayWithErrorHandling

File: C:\xampp\htdocs\testowy\vendor\twig\twig\lib\Twig\Template.php
Line: 411
Function: display

File: C:\xampp\htdocs\testowy\vendor\twig\twig\lib\Twig\Environment.php
Line: 363
Function: render

File: C:\xampp\htdocs\testowy\application\libraries\Twig.php
Line: 149
Function: render

File: C:\xampp\htdocs\testowy\application\libraries\Twig.php
Line: 131
Function: render

File: C:\xampp\htdocs\testowy\application\controllers\admin\User.php
Line: 59
Function: display

File: C:\xampp\htdocs\testowy\index.php
Line: 315
Function: require_once


Jak się tego pozbyć?
Go to the top of the page
+Quote Post
b4rt3kk
post
Post #2





Grupa: Zarejestrowani
Postów: 1 933
Pomógł: 460
Dołączył: 2.04.2010
Skąd: Lublin

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


Zerknij do pliku i linii, na które wskazuje błąd:

  1. Filename: Session/Session.php
  2.  
  3. Line Number: 879
Go to the top of the page
+Quote Post
phpion
post
Post #3





Grupa: Moderatorzy
Postów: 6 072
Pomógł: 861
Dołączył: 10.12.2003
Skąd: Dąbrowa Górnicza




Problem chyba leży u Ciebie troszkę gdzie indziej. Wiadomości flash służą do jednokrotnego wyświetlania treści po przekierowaniu. Ty dodajesz wiadomość flash i wyświetlasz szablon. Jeśli tak to nie rób flasha tylko przekaz komunikat do widoku albo zostaw flash ale zrób przekierowanie.
Go to the top of the page
+Quote Post
codeszan
post
Post #4





Grupa: Zarejestrowani
Postów: 61
Pomógł: 0
Dołączył: 2.07.2017

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


phpion rzeczywiście tu jest problem lecz nie wiem jak sobie z nim poradzić.

Wersja 1: Nie komunikat jest w sesji po stronie widoku ale go nie pokazuje
  1. //po kliknieciu przycisku
  2. if ($action) {
  3. if ($this->form_validation->run() == FALSE) {
  4. //nie stworzone konto
  5. $this->session->set_flashdata('item', array('message' => strip_tags(validation_errors()), 'class' => 'danger'));
  6. redirect('admin/user/create');
  7.  
  8. }
  9. ...


Wersja2: Gdy zrobie:
  1. redirect('admin/user/index');

komunikat zostaje wyświetlony 1 raz (czyli jak ma byc), jednak chcialem by byl on w miejscu z formularzem do od tworzenia czyli admin/user/create

Idąc w drugą strone i metoda z przeslaniem do wiodku przez twiga:

  1. $this->session->set_flashdata('item', array('message' => strip_tags(validation_errors()), 'class' => 'danger'));
  2. $this->twig->addGlobal("session", $this->session);
  3. $this->twig->display('admin/index');

Komunikat jest ale dopiero przy 3 kliknieciu znika.


Obstwał bym, że pierwszy sposob jest lepszy tylko nie zwraca fizycznie komunikatu.
tj. dump z sesj:
var_dump($_SESSION);
  1. array(4) { ["__ci_last_regenerate"]=> int(1520081544) ["logged_in"]=> array(2) { ["id"]=> string(1) "1" ["online"]=> bool(true) } ["item"]=> array(2) { ["message"]=> string(29) "The Email field is required. " ["class"]=> string(6) "danger" } ["__ci_vars"]=> array(1) { ["item"]=> string(3) "old" } }

dump(session)
  1. NULL


pętla wyświetlająca:
  1. {% if session.flashdata.item and session.flashdata.item['message'] is not empty %}
  2. <div class="alert alert-{{ session.flashdata.item['class'] }} alert-dismissable"
  3. role="alert">
  4. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
  5. aria-hidden="true"
  6. style="color: #000;">×</span>
  7. </button>
  8. <p class="alert-body">{{ session.flashdata.item['message'] }}</p>
  9. </div>
  10. {% endif %}
Go to the top of the page
+Quote Post
nospor
post
Post #5





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




Cytat
Idąc w drugą strone i metoda z przeslaniem do wiodku przez twiga: [....]Komunikat jest ale dopiero przy 3 kliknieciu znika.

Ty do twig nie miales przekazywac flasha... Ty miales przekazac poprostu zwykly tekst bedacy komunikatem bledu. Flasha juz nie ustawiaj. Na tym polegalo to rozwiazanie.
Go to the top of the page
+Quote Post

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: 22.08.2025 - 19:12