CodeIgniter Forums
Page logic - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Page logic (/showthread.php?tid=2004)



Page logic - El Forum - 07-11-2007

[eluser]magicPants[/eluser]
Hi,

I'm trying to design/build a timesheet application using CI (I'm a newbie to CI) and have broken the classes down into the following: project, task, activity & resource. The concept is: an activity will record the time spent on a certain task for a project.

In order to view the list of activities for a project/task I would like to do something like:

List all activities for task 'x' under project 'y':
/timesheet/index.php/activity/projectY/taskX/

or

List all activities for project 'y':
/timesheet/index.php/activity/projectY/

What's the nest way to achieve this within my activity class?

TIA

Dave


Page logic - El Forum - 07-11-2007

[eluser]OwanH[/eluser]
Hey,

I'd suggest implementing a function within your activity controller class which accepts two arguments, the first being an identifier indicating which project you want to list activities for, the second being an identifier indicating the task. The second argument can be optional and can be assigned a default value. That way, this single function will handle either situation: project only or project and task.

So, if we let the name of your function be, say, viewlist for example then you could end up with the following:

List all activities for task 'x' under project 'y':
/timesheet/index.php/activity/viewlist/projectY/taskX/

or

List all activities for project 'y':
/timesheet/index.php/activity/viewlist/projectY/

and so the viewlist function in the activity class would be like so,

Code:
<?php
class Activity extends Controller {

  ...

  function viewlist($project_id, $task_id = "")
  {
    // check if a task ID was specified in the URL
    if (empty($task_id))
    {
      // handle the case where only the project is specified
      ...
    }
    else {
      // handle the case where both the project and task are specified
      ...
    }
    ...
  }

}
?>