View Single Post
  #2 (permalink)  
Old 12-11-2007, 01:58 AM
conradwt conradwt is offline
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
Reply With Quote