Another Noob Question (Undefined Index Error)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manasia
Forum Newbie
Posts: 2
Joined: Mon Nov 09, 2009 2:18 pm

Another Noob Question (Undefined Index Error)

Post by manasia »

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hello World.

I am having problems getting this dynamic index.php working. In the error log I get the following error:

PHP Notice: Undefined index: p in /usr/home/hearbr/www/htdocs/APP/Front/Controller/Default.php on line 2

I know that means that p is not defined, but what is crazy is that this works on my old host, that is running PHP 5.2.11 and the new one is running PHP 5.2.6.

I tried doing an ifsset but it did not work either any help would be appreciated here is the entire function:

Code: Select all

function actionIndex(){
        switch ($this->get['p']){
            case 'ourstaff':
                $content=$this->_page->find(2);
                $view=array(
                    'title'=>$content['title'],
                    'content'=>$content['content'],
                );
                $this->display($view,'ourStaff');
                break;
            case 'forms':
                $content=$this->_page->find(3);
                $view=array(
                    'title'=>$content['title'],
                    'content'=>$content['content'],
                );
                $this->display($view,'forms');
                break;
            case 'insurance':
                $content=$this->_page->find(4);
                $view=array(
                    'title'=>$content['title'],
                    'content'=>$content['content'],
                );
                $this->display($view,'insurance');
                break;
            case 'services':
                $content=$this->_page->find(5);
                $view=array(
                    'title'=>$content['title'],
                    'content'=>$content['content'],
                );
                $this->display($view,'services');
                break;
            case 'products':
                $content=$this->_page->find(6);
                $view=array(
                    'title'=>$content['title'],
                    'content'=>$content['content'],
                );
                $this->display($view,'products');
                break;
            case 'contactus':
                $content=$this->_page->find(7);
                $view=array(
                    'title'=>$content['title'],
                    'content'=>$content['content'],
                );
                $this->display($view,'contactUs');
                break;
            case 'wecanhelp':
                $content=$this->_page->find(8);
                $view=array(
                    'title'=>$content['title'],
                    'content'=>$content['content'],
                );
                $this->display($view,'weCanHelp');
                break;
            default:
                $content=$this->_page->find(1);
                $view=array(
                    'content'=>$content['content'],
                );
                $this->display($view);
        } 
    }

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Another Noob Question (Undefined Index Error)

Post by pickle »

Different installations of PHP can have different levels of error reporting. Apparently your old host didn't report errors of type E_NOTICE, whereas the new one does.

Wrapping your switch() with if(isset($this->get['p'])) should stop the error.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
manasia
Forum Newbie
Posts: 2
Joined: Mon Nov 09, 2009 2:18 pm

Re: Another Noob Question (Undefined Index Error)

Post by manasia »

I figured out why I was getting the error. The new host does not support the Zend framework.
Post Reply