Answers.Body: <p>When calling services, you should not include "service" in method name.</p>
  
  <p>Try <code>return craft()-&gt;myPlugin_other-&gt;testing();</code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-04T20:17:20.973Z
Answers.Text: Oops, I knew that. Mistake when typing up question! I still get "Property "Craft\WebApp.myPlugin_other" is not defined."
Answers.UserDisplayName: taylor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-04T20:25:02.667Z
Answers.Text: @Zack I think the methods are case-sensitive, so double check spelling mistakes.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-04T20:50:30.360Z
Answers.Text: I've tried all lowercase, camel, upper camel, not having any luck. By default Craft will include all files inside /service right? Or do I need to declare the added files?
Answers.UserDisplayName: taylor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-04T20:52:29.040Z
Answers.Text: Just tried in the service file and it worked. I was getting the error when trying to call craft->myPlugin_Other->testing(); in the myPluginVariable.php file. Are the extra service files only accessible from the main service file?
Answers.UserDisplayName: taylor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-04T20:54:13.627Z
Answers.Text: No, I have plugins with multiple service files and they work fine. I wonder if Craft defaults to the MyPluginService file if it exists. Can you try renaming that one to MyPlugin_MainService.php and seeing if that allows you to call other services?
Answers.UserDisplayName: Aaron Berkowitz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-04T21:04:19.327Z
Answers.Text: I played around some more and now it's working in the variables file too. No idea how it was working in service but not variable before (was copy/pasting the return line.) Seems like it was a formatting problem, I was getting tripped up by longer service names like "MyPlugin_OtherFile". The formatting that worked everywhere was lower camel for the pugin name, then lower camel again for the latter part of the file name: return craft->myPlugin_otherFile->myfunction();
Answers.UserDisplayName: taylor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-04T19:20:01.480Z
Answers.LastActivityDate: 2015-03-04T19:20:01.480Z
Answers.UserDisplayName: Aaron Berkowitz
Answers.Body: <p>Adding my own discovery in case anyone ever runs into this. The format that worked was lower camel for both the plugin name, and also lower camel for the secondary name.</p>
  
  <p>So for the following class:</p>
  
  <pre><code>class MyPlugin_OtherService extends BaseApplicationComponent
  {
      public function myfunction() {}
  }
  </code></pre>
  
  <p>I was able to access it like:</p>
  
  <pre><code>return craft()-&gt;myPlugin_other-&gt;myfunction();
  </code></pre>
  
  <p>For a longer name, like:</p>
  
  <pre><code>class MyPlugin_MoreFunctionalityService extends BaseApplicationComponent
  {
      public function myfunction() {}
  }
  </code></pre>
  
  <p>The formatting should look like:</p>
  
  <pre><code>return craft()-&gt;myPlugin_moreFunctionality-&gt;myfunction();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-04T21:12:37.350Z
Answers.LastActivityDate: 2015-03-04T21:12:37.350Z
Answers.UserDisplayName: taylor
Body: <p>I'm not sure if I missed documentation on it, but is there a method to follow when including additional plugin files for services, controllers, variables etc.? </p>
  
  <p>For bigger plugins it'd help to do this, something like</p>
  
  <pre><code>- /myplugin
     -/services
        -MyPluginService.php
        -MyPlugin_OtherService.php
        -MyPlugin_AnotherService.php
  </code></pre>
  
  <p>I've tried doing this and being sure to follow the service structure of:</p>
  
  <pre><code>namespace Craft;
  
  class MyPlugin_OtherService extends BaseApplicationComponent
  {
  
    public function testing()
    {
        return "success!";
    }
  
  }
  </code></pre>
  
  <p>But when trying to access it from say the myPluginVariable.php file, I get the CException error that the property is not defined.</p>
  
  <pre><code>return craft()-&gt;myPlugin_OtherService-&gt;testing();
  </code></pre>
  
  <p>Is there a step I'm missing? Do I need to declare these extra files somewhere so that they are included?</p>
  
Tags: <plugin-development><php><include><function>
Title: Multiple Service/Variable/Controller plugin files
ThreadText: # Multiple Service/Variable/Controller plugin files
  
  (Asked by: username_0 on 2015-03-04)
  
  I'm not sure if I missed documentation on it, but is there a method to follow when including additional plugin files for services, controllers, variables etc.?
  
  For bigger plugins it'd help to do this, something like
  
  ```
  - /myplugin
     -/services
        -MyPluginService.php
        -MyPlugin_OtherService.php
        -MyPlugin_AnotherService.php
  
  ```
  
  I've tried doing this and being sure to follow the service structure of:
  
  ```
  namespace Craft;
  
  class MyPlugin_OtherService extends BaseApplicationComponent
  {
  
    public function testing()
    {
        return "success!";
    }
  
  }
  
  ```
  
  But when trying to access it from say the myPluginVariable.php file, I get the CException error that the property is not defined.
  
  ```
  return craft()->myPlugin_OtherService->testing();
  
  ```
  
  Is there a step I'm missing? Do I need to declare these extra files somewhere so that they are included?
  
  **Tags:** plugin-development, php, include, function
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-03-04. Score: 2 | Accepted answer
  
  When calling services, you should not include "service" in method name.
  
  Try `return craft()->myPlugin_other->testing();`
  
  > **Comments:**
  > **username_0**: Oops, I knew that. Mistake when typing up question! I still get "Property "Craft\WebApp.myPlugin_other" is not defined."  
  > **username_2**: @Zack I think the methods are case-sensitive, so double check spelling mistakes.  
  > **username_0**: I've tried all lowercase, camel, upper camel, not having any luck. By default Craft will include all files inside /service right? Or do I need to declare the added files?  
  > **username_0**: Just tried in the service file and it worked. I was getting the error when trying to call craft->myPlugin_Other->testing(); in the myPluginVariable.php file. Are the extra service files only accessible from the main service file?  
  > **username_1**: No, I have plugins with multiple service files and they work fine. I wonder if Craft defaults to the MyPluginService file if it exists. Can you try renaming that one to MyPlugin_MainService.php and seeing if that allows you to call other services?  
  > **username_0**: I played around some more and now it's working in the variables file too. No idea how it was working in service but not variable before (was copy/pasting the return line.) Seems like it was a formatting problem, I was getting tripped up by longer service names like "MyPlugin_OtherFile". The formatting that worked everywhere was lower camel for the pugin name, then lower camel again for the latter part of the file name: return craft->myPlugin_otherFile->myfunction();  
  
  ---
  
  ### Answer by username_0 on 2015-03-04. Score: 2
  
  Adding my own discovery in case anyone ever runs into this. The format that worked was lower camel for both the plugin name, and also lower camel for the secondary name.
  
  So for the following class:
  
  ```
  class MyPlugin_OtherService extends BaseApplicationComponent
  {
      public function myfunction() {}
  }
  
  ```
  
  I was able to access it like:
  
  ```
  return craft()->myPlugin_other->myfunction();
  
  ```
  
  For a longer name, like:
  
  ```
  class MyPlugin_MoreFunctionalityService extends BaseApplicationComponent
  {
      public function myfunction() {}
  }
  
  ```
  
  The formatting should look like:
  
  ```
  return craft()->myPlugin_moreFunctionality->myfunction();
  
  ```
  
  
  ---
  
  