views:

46

answers:

1

I'm new to zend so I'm not sure what's the best way to organize what I'm trying to do. I direct the user to a series of quizzes. mysite.com/quiz1 mysite.com/quiz2 mysite.com/quiz3 mysite.com/quiz4

When the user answers the first quiz, he is forwarded to a page that tells him if his answer is correct, and on the same page he can choose to answer another quiz. If he answers it, he again will be taken to a page where he is told if his answer was correct and presented with the third quiz.

From the architecture side of things, are each of these quiz1, quiz2, etc. pages considered a controller of their own? Their path says they may be, but doesn't make sense to me if they are. Is there a way to have them at those same paths but bundle them in the same controller. As I said I'm new to Zend so would appreciate some feedback about the right way to do this.

+5  A: 

I would do a Quiz controller that will have actions like showQuiz(), validateQuiz() that will read the quiz parameter. This way you will reuse most of the code. The quizes will be entries in the db and there you can also build paths or connections with them.

class QuizController extends Zend_Controller_Action 
{
     public function showAction()
     {
          // you can play this in routes but it could be basically something like this
          // localhost/quiz/id/1
          $quiz_id = $this->_request->getParam('id'); 
          $this->view->quiz = $this->getQuizTable()->find($quiz_id);
     }

     public function validateAction()
     {
          $quiz_id = $this->_request->getParam('id'); 
          $quiz = $this->getQuizTable()->find($quiz_id);
          $quiz->validate(); // build your own validator function
     }
}
Elzo Valugi
Nice approach! Just why not making the controller REST-ful? You could rename your showAction() to getAction() and validateAction() to postAction(), and end up with much cleaner URLs and other perks suggested by REST.
Vika