I am learning MVC and was wondering about a particular problem that I have came across, below is my code from one of controller's methods.

public function psn($params) {

    # There are parameters supplied - we are getting a single item
    if ($params) {


    # There are no parameters supplied - show all items
    } else {


    }
}

As you can see above the method psn can allow parameters to fetch a single item or if no parameters are defined it will fetch all items.

Am I doing this correctly? It is almost as if the psn method needs both an index method and a get item method but I am kinda putting it into one method.

How would I go about doing this? Would multiple controllers be an idea that would be plausible?

Thanks,

EDIT

Would it be plausible to do something like below;

public function psn($params) {

    # There are parameters supplied - we are getting a single item
    if ($params) {

         # Call private method psnGetOne

    # There are no parameters supplied - show all items
    } else {

         # Call private method psnGetAll
    }
}

Related posts

Recent Viewed