Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>@John Galt, I suppose it's not an exact duplicate but it is very similar and the resolution does appear to apply to your situation very directly. The other technique you could consider using would be to instantiate the Library in the controller and than give it a reference of the model.</p> <pre><code>class TestController extends AppController { function index(){ App::uses('TheLibrary', 'Lib'); $obj = new TheLibrary(); $obj-&gt;GivenModel = &amp;$this-&gt;GivenModel; } } </code></pre> <p>-EDIT- And then within the library you've written do something like this.</p> <pre><code>class TheLibrary { var $GivenModel = null; function some_query(){ return $this-&gt;GivenModel-&gt;query('SELECT * FROM like_some_table_dude WHERE 1'); } } </code></pre> <p>The first code snippet is of the Controller instantiating your library and then giving the library a reference to the Model as the property GivenModel. The "&amp;" symbol makes the assignment a reference (see <a href="https://stackoverflow.com/questions/999333/how-does-the-symbol-in-php-affect-the-outcome">How does the &#39;&amp;&#39; symbol in PHP affect the outcome?</a>). The second code snippet is of a sample of how the library would use that property.</p> <p>I do understand that you are trying to use a model from the library and that is what the solution you have in your edit and my proposed solution both do. However I will note again that this is not proper MVC convention and you should reconsider how you are using Libraries. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload