Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2007, 12:40 PM
San San is offline
Junior Member
 
Join Date: Feb 2007
Posts: 1
Default How can handle Messages??

Hi all,
How u were handling success/failure/error like messages in ZF projects
Thanks
San.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-08-2007, 12:34 PM
Junior Member
 
Join Date: Feb 2007
Posts: 2
Default

I am not quite sure i fully understand what you want to find out.

Anyway, I think best approach is by using try-catch mechanism from PHP5.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-10-2007, 07:21 PM
Junior Member
 
Join Date: Feb 2007
Location: United States
Posts: 7
Default

In general if I was using the mvc method, I would throw exceptions and catch them in a higher level in the application. If an exception is not caught then have the controller save it, so we can check for uncaught exceptions later and give our own error message to the user. It is also a good to store uncaught exceptions to a logger for analysis.

As for errors, I have a custom error handler which saves all errors to a buffer object until after execution of dispatch process has finished. The error system is too complicated for me to explain right now, but this way we can handle problems more efficiently.

Last edited by potatobob : 02-10-2007 at 07:24 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 05-14-2007, 11:34 PM
Junior Member
 
Join Date: May 2007
Posts: 25
Default error handling

i use this very simple helper to handle my errors. it saves the errors to a session so you dont have to worry about redirects clearing the error.

PHP Code:
<?php
class libErrors
{
    private 
$ns;
    private 
$errors;
    
    function 
__construct()
    {
        
$this->ns = new Zend_Session_Namespace('errors'); 
        
$this->errors $this->ns->errors;   
    }
    
    function 
clear()
    {
        unset(
$this->errors);
        
$this->updateNs();
    }
    
    function 
add($error)
    {
        
$this->errors[] = $error;
        
$this->updateNs();
    }
    
    function 
hasErrors()
    {
        if(
count($this->errors) > 0){
            return 
true;
        }
    }
    
    function 
get()
    {
        return 
$this->errors;
    }
    
    private function 
updateNs()
    {
        
$this->ns->errors $this->errors;
    }
}
i then use this view helper, renderAlert (which handles both errors and messages to the user)

PHP Code:
    public function RenderAlert(){
        
$m = new libMessage();
        
$e = new libErrors();
        
$alert false;
        
$view Zend_Registry::get('view');
        
        if(
$m->hasMessage() || $e->hasErrors()){
            if(
$m->hasMessage()){
                
$message "<p>" $m->get() . "</p>";
            }
            
            if(
$e->hasErrors()){
                
$error "<p>The following errors have occurred:</p>" $view->HtmlList($e->get());
            }
            
$alert "<div class='message_box'>" $message $error "</div>";
        }
        
        
//after this renders it clears the errors and messages
        
$m->clear();
        
$e->clear();
        
        return 
$alert;
    } 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 05-29-2007, 05:10 PM
Dead_Thinker's Avatar
Junior Member
 
Join Date: May 2007
Location: Fortaleza/Ceará/Brazil
Posts: 20
Send a message via ICQ to Dead_Thinker Send a message via Yahoo to Dead_Thinker Send a message via Skype™ to Dead_Thinker
Default

Quote:
Originally Posted by frosty1 View Post
i use this very simple helper to handle my errors. it saves the errors to a session so you dont have to worry about redirects clearing the error.

PHP Code:
<?php
class libErrors
{
    private 
$ns;
    private 
$errors;
    
    function 
__construct()
    {
        
$this->ns = new Zend_Session_Namespace('errors'); 
        
$this->errors $this->ns->errors;   
    }
    
    function 
clear()
    {
        unset(
$this->errors);
        
$this->updateNs();
    }
    
    function 
add($error)
    {
        
$this->errors[] = $error;
        
$this->updateNs();
    }
    
    function 
hasErrors()
    {
        if(
count($this->errors) > 0){
            return 
true;
        }
    }
    
    function 
get()
    {
        return 
$this->errors;
    }
    
    private function 
updateNs()
    {
        
$this->ns->errors $this->errors;
    }
}
i then use this view helper, renderAlert (which handles both errors and messages to the user)

PHP Code:
    public function RenderAlert(){
        
$m = new libMessage();
        
$e = new libErrors();
        
$alert false;
        
$view Zend_Registry::get('view');
        
        if(
$m->hasMessage() || $e->hasErrors()){
            if(
$m->hasMessage()){
                
$message "<p>" $m->get() . "</p>";
            }
            
            if(
$e->hasErrors()){
                
$error "<p>The following errors have occurred:</p>" $view->HtmlList($e->get());
            }
            
$alert "<div class='message_box'>" $message $error "</div>";
        }
        
        
//after this renders it clears the errors and messages
        
$m->clear();
        
$e->clear();
        
        return 
$alert;
    } 

I think that's very interesting, i have made something like this. I have a utility class, and one of its methotds is a message method who puts a class (for icon), title and message on session, and i have a "session" on my header who show the message, another way to show the message is using javascript, a few effects with Script.aculo.us made it a lot more pretty
People here thinks thats cool. And we are making the second system with that.

Sorry for my english.
P.S.: I love to have found that forum.
Hugs.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-04-2008, 05:16 AM
Junior Member
 
Join Date: Jan 2008
Posts: 9
Default

Thank you very much
__________________
موقع -
برامج -
وصلات
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-08-2008, 10:35 AM
Member
 
Join Date: Aug 2007
Location: Sweden
Posts: 47
Send a message via MSN to Leif.Högberg
Default

You might also want to take a look at the action helper flashMessenger.
Although it doesn't come with a view helper to match one can be easily written and together they would accomplish more or less the same thing as the suggestions above.

Note: Just to make it clear. You would need to manualy feed the flashMessenger with the errors you'd want to display to the user.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:13 AM.