• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Page logic

#1
[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

#2
[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
      ...
    }
    ...
  }

}
?>


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.