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


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-06-2007, 06:01 AM
Member
 
Join Date: Nov 2007
Posts: 33
Question View Renders For Non-Existent Database ID

Hi, I have the following code in my showAction:

PHP Code:
function showAction() {

        
$this->view->title "Show Episode"

        
$episode = new Episode();
        
        
$id 0;

        if ( 
$this->_request->isPost() ) {

            
Zend_Loader::loadClass('Zend_Filter_Alpha');
            
$filter = new Zend_Filter_Alpha();

            
$id = (int)$this->_request->getPost'id' );

        } else {

            
$id = (int)$this->_request->getParam'id' );
        
        }
        
        if ( 
$id ) {
            
// Only render if we have an id and can find the episode.
            
$this->view->episode $episode->find$id );

            if ( 
$this->view->episode->id ) {
                
$this->view->documentRoot '/public';
                
$this->view->absolute_update_path '/public' '/updates/' $this->view->episode->update_dir;
                return;
            }
            
        }
        else {
            
            
// Redirect to the index page.
            
$this->_redirect'/admin/list' );
            return;
            
        }
        

    } 
However, it renders the associated view (i.e. show.phtml) even if the id doesn't exist in the database. Thus, does anyone see an issue in the code above? BTW, I tried using fetchRow as well and it produced the same result.

Thanks in advance,

-Conrad
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-11-2007, 12:58 AM
Member
 
Join Date: Nov 2007
Posts: 33
Lightbulb [SOLUTION] View Renders For Non-Existent Database ID

Quote:
Originally Posted by conradwt View Post
Hi, I have the following code in my showAction:

PHP Code:
function showAction() {

        
$this->view->title "Show Episode"

        
$episode = new Episode();
        
        
$id 0;

        if ( 
$this->_request->isPost() ) {

            
Zend_Loader::loadClass('Zend_Filter_Alpha');
            
$filter = new Zend_Filter_Alpha();

            
$id = (int)$this->_request->getPost'id' );

        } else {

            
$id = (int)$this->_request->getParam'id' );
        
        }
        
        if ( 
$id ) {
            
// Only render if we have an id and can find the episode.
            
$this->view->episode $episode->find$id );

            if ( 
$this->view->episode->id ) {
                
$this->view->documentRoot '/public';
                
$this->view->absolute_update_path '/public' '/updates/' $this->view->episode->update_dir;
                return;
            }
            
        }
        else {
            
            
// Redirect to the index page.
            
$this->_redirect'/admin/list' );
            return;
            
        }
        

    } 
However, it renders the associated view (i.e. show.phtml) even if the id doesn't exist in the database. Thus, does anyone see an issue in the code above? BTW, I tried using fetchRow as well and it produced the same result.

Thanks in advance,

-Conrad
The issue that I was experiencing was that I was using the default view (i.e. show.phtml) instead of redirecting to /admin/list after

PHP Code:
    if ( $this->view->episode->id ) {
         
$this->view->documentRoot '/public';
         
$this->view->absolute_update_path '/public' '/updates/' .        $this->view->episode->update_dir;
                return;
            } 
Thus, I refactored the code to redirect to /admin/list when the id doesn't exist in the database.

-Conrad
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 06:36 AM.