title: CAKEPHP. How to invoke a controller method into a controller?
body: <p>I'm designing an app in which all entities (articles, suppliers, customers, contacts, etc.) have a special object called, well... Object (each row of each table have an object_id column). I thought this because there are a lot common behaviors and relations that can be invoked to all entities in the same way (ex. audit trail, object_id=32665, user_id=312, detail=update_field, bla bla).</p>
  <p>So, I want to create a Component with a method (maybe create_new_object) that will call add method from Objects Controller (I altered that method to create a new entity without human interaction, my code below).</p>
  <p>Is it a good idea? How can I to call a Controller method from a Component?</p>
  <p><strong>Edition</strong></p>
  <p>I forgot to put my code, my apologies.</p>
  <p>This is my ObjectController</p>
  <pre><code>&lt;?php
  namespace App\Controller;
  
  use App\Controller\AppController;
  
  class ObjectsController extends AppController
  {
     public function add($type = null)
      {       
          if($type)
          {
              $object = $this-&gt;Objects-&gt;newEntity();
              
              $object = $this-&gt;Objects-&gt;patchEntity($object, $this-&gt;request-&gt;getData());
              
              $object-&gt;type = $type;
              
              if ($this-&gt;Objects-&gt;save($object)) {
                  $this-&gt;Flash-&gt;success(__('The object has been saved.'));
  
                  $resultJ = json_encode(array('result' =&gt; 'success',
                                               'object_id' =&gt; $object-&gt;id));
              }
              else
              {
                  $resultJ = json_encode(array('result' =&gt; 'error',
                                               'message' =&gt; 'The object could not be save. Please, try again.'));
              }
          }
          else
          {
              $resultJ = json_encode(array('result' =&gt; 'error',
                                           'message' =&gt; 'An object type is necessary. Please, try again.o'));
          }
              
          $this-&gt;response-&gt;type('json');
                  
          $this-&gt;response-&gt;body($resultJ);
                  
          return $this-&gt;response;
      }
  }
  </code></pre>
  <p>I have three important entities...</p>
  <ol>
  <li>Articles.</li>
  <li>Customers.</li>
  <li>Suppliers.</li>
  </ol>
  <p>Then, I have another kind of entities (I called them, secondary order), live Contacts, Addresses, Telephones, emails, Cities, Countries, etc.</p>
  <p>Each object of each entity (main and secondary) must have an object_id property referred to an Object object () this will be useful for audit trailfor example. So, I'm planning to create a Component, called IdentificationComponent with this content...</p>
  <pre><code>public function create_and_object()
  {
      bla bla bla... Object-&gt;add($type_of_object);
      
      return $generated_object_id;
  }
  </code></pre>
  <p>Finally, I want to implement my Component in AppController (with a specific exception for ObjectController). I hope that each entity creates a new Object
  object when they are created.</p>