Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flashSession->getMessages(type, BOOLEAN remove) removed all messages #1575

Closed
romanlex opened this issue Nov 21, 2013 · 3 comments
Closed

flashSession->getMessages(type, BOOLEAN remove) removed all messages #1575

romanlex opened this issue Nov 21, 2013 · 3 comments

Comments

@romanlex
Copy link

I'm use Flash\Session for ajax response. Code is her: http://pastebin.com/JVVenCLx
In my code I get messages by type:

$_successMessages = $this->flashSession->getMessages('success', false);
$_errorMessages = $this->flashSession->getMessages('error', false);
$_warningMessages = $this->flashSession->getMessages('warning', false);
$_noticeMessages = $this->flashSession->getMessages('notice', false);

Example:
If I send Form twice or more and in first time I get success message, in second time I get error messages...my $messages[] will contains all messages from different Ajax request :(

If I use boolean $remove flag in method:

$_successMessages = $this->flashSession->getMessages('success', true);

I don't get another messages in request :( because In first string I remove all another messages.

Example:
I send Form and get Succes and Notice messages. When I call getMessages('success', true) method - I remove all messages in Session, and I can not get Notice messages from another string

I think what removed messages should belong to the type that is caused by the method of getMessage(type)....For remove all messages must be another method.

@ghost ghost mentioned this issue Nov 22, 2013
phalcon pushed a commit that referenced this issue Nov 22, 2013
@phalcon
Copy link
Collaborator

phalcon commented Nov 22, 2013

Fixed in 1.3.0

@phalcon phalcon closed this as completed Nov 22, 2013
@romanlex
Copy link
Author

how I can get fix on 1.2.4? ;)

@ghost
Copy link

ghost commented Nov 28, 2013

diff --git a/ext/flash/session.c b/ext/flash/session.c
index 7b24e4d..43d6a97 100644
--- a/ext/flash/session.c
+++ b/ext/flash/session.c
@@ -208,6 +208,7 @@ PHP_METHOD(Phalcon_Flash_Session, message){
 PHP_METHOD(Phalcon_Flash_Session, getMessages){

        zval *type = NULL, *remove = NULL, *messages, *return_messages;
+       zval *do_remove;

        PHALCON_MM_GROW();

@@ -221,15 +222,30 @@ PHP_METHOD(Phalcon_Flash_Session, getMessages){
                PHALCON_INIT_VAR(remove);
                ZVAL_BOOL(remove, 1);
        }
-       
+
+       if (Z_TYPE_P(type) != IS_NULL) {
+               PHALCON_INIT_VAR(do_remove);
+               ZVAL_FALSE(do_remove);
+       }
+       else {
+               do_remove = remove;
+       }
+
        PHALCON_INIT_VAR(messages);
-       phalcon_call_method_p1(messages, this_ptr, "_getsessionmessages", remove);
-       if (Z_TYPE_P(messages) == IS_ARRAY) { 
-               if (likely(Z_TYPE_P(type) == IS_STRING)) {
+       phalcon_call_method_p1(messages, this_ptr, "_getsessionmessages", do_remove);
+       if (Z_TYPE_P(messages) == IS_ARRAY) {
+               if (likely(Z_TYPE_P(type) != IS_NULL)) {
                        if (phalcon_array_isset(messages, type)) {
                                PHALCON_OBS_VAR(return_messages);
                                phalcon_array_fetch(&return_messages, messages, type, PH_NOISY);
-                               RETURN_CCTOR(return_messages);
+                               RETVAL_ZVAL(return_messages, 1, 0);
+                               if (zend_is_true(remove)) {
+                                       phalcon_array_unset(&messages, type, 0);
+                                       phalcon_call_method_p1_noret(this_ptr, "_setsessionmessages", messages);
+                               }
+
+                               PHALCON_MM_RESTORE();
+                               return;
                        }

                        RETURN_MM_EMPTY_ARRAY();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant