Answers.Body: <p>Have you defined the settings and their type in your Task file?</p>
  
  <p>I've had success using the array of things passed to the task to set the total steps like so:</p>
  
  <pre><code>class RerouteTask extends BaseTask
  {
  
    protected function defineSettings()
    {
      // Files passed from controller
        return array(
          'files' =&gt; AttributeType::Mixed,
        );
    }
  
    public function getTotalSteps()
    {
      return count( $this-&gt;getSettings()-&gt;files );
    }
  </code></pre>
  
  <p>Then inside a controller you create the task.</p>
  
  <pre><code>$task = craft()-&gt;tasks-&gt;createTask('Reroute', 'Importing routes', array(
    'files' =&gt; $files
  ));
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-24T13:20:08.783Z
Answers.Text: Thanks that did the trick. However i find it strange why it didn't work with public properties and trying to set them like $task->property = "test" i am pretty new to this but that seems like normal OOP if you would like can you explain this behavior?
Answers.UserDisplayName: Jacob
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-24T10:16:20.107Z
Answers.LastActivityDate: 2016-05-24T10:16:20.107Z
Answers.UserDisplayName: Luke Pearce
Body: <p>How am I able to get or set additional properties on a Task model inside a plugin.
  Eventually I would like to influence the <code>Totalsteps</code> of a task.</p>
  
  <pre><code>$task = craft()-&gt;tasks-&gt;createTask('Reroute', 'Importing routes', array(
      'files' =&gt; $files,
      'steps' =&gt; count($files)
  ));
  
  class RerouteTask extends BaseTask
  {
      public function getTotalSteps()
      {
          return $this-&gt;getSettings()-&gt;steps;
      }
  </code></pre>
  
  <p>Is resulting in <code>Craft\TaskModel.steps is not defined</code>.
  What am I missing here?</p>
  
Tags: <plugin-development><control-panel><tasks>
Title: How can I access or set a Task's properties inside a class or method?
ThreadText: # How can I access or set a Task's properties inside a class or method?
  
  (Asked by: username_0 on 2016-05-24)
  
  How am I able to get or set additional properties on a Task model inside a plugin.
  Eventually I would like to influence the `Totalsteps` of a task.
  
  ```
  $task = craft()->tasks->createTask('Reroute', 'Importing routes', array(
      'files' => $files,
      'steps' => count($files)
  ));
  
  class RerouteTask extends BaseTask
  {
      public function getTotalSteps()
      {
          return $this->getSettings()->steps;
      }
  
  ```
  
  Is resulting in `Craft\TaskModel.steps is not defined`.
  What am I missing here?
  
  **Tags:** plugin-development, control-panel, tasks
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-05-24. Score: 2 | Accepted answer
  
  Have you defined the settings and their type in your Task file?
  
  I've had success using the array of things passed to the task to set the total steps like so:
  
  ```
  class RerouteTask extends BaseTask
  {
  
    protected function defineSettings()
    {
      // Files passed from controller
        return array(
          'files' => AttributeType::Mixed,
        );
    }
  
    public function getTotalSteps()
    {
      return count( $this->getSettings()->files );
    }
  
  ```
  
  Then inside a controller you create the task.
  
  ```
  $task = craft()->tasks->createTask('Reroute', 'Importing routes', array(
    'files' => $files
  ));
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks that did the trick. However i find it strange why it didn't work with public properties and trying to set them like $task->property = "test" i am pretty new to this but that seems like normal OOP if you would like can you explain this behavior?  
  
  ---
  
  