title: cakePHP Calling functions between models/controllers
body: <p>I am a relative newbie, so this may be blindingly obvious to most of you, but not to me!</p>
  
  <p>I have 3 models (for this problem)</p>
  
  <p>Project, ProjectDataset, and UserSessionDownload</p>
  
  <p>A view in Project calls controller UserSessionDownloads to make a record of the download in a log table (working well thanks to help from Steve Moseley here) and then does the download.  To download the file, the full pathname for the file is required.</p>
  
  <p>So the UserSessionDownload function then calls the Model/Controller for ProjectDataset to get the filename for the chosen ProjectDataset (identified by id).</p>
  
  <p>This filename will be then used to get the file in question.</p>
  
  <p>Code parts are as follows:
  In Project view:</p>
  
  <pre><code>echo $this-&gt;Html-&gt;Link('Add a Ref', array('controller'=&gt;'UserSessionDownloads', 'action'=&gt;'add_download',$project_dataset['id'],$project['Project']['id']));
  </code></pre>
  
  <p>In UserSessionDownloads the function "add_download" then calls a function in ProjectDataset thusly (I have loaded ProjectDataset model into this function):</p>
  
  <pre><code>$filename = $this-&gt;ProjectDataset-&gt;get_filename($this-&gt;request-&gt;params['pass'][0]);
  </code></pre>
  
  <p>(the params refers to id of dataset passed in by call from Project view)</p>
  
  <p>Now, I have tried the get_filename function being in Model and Controller files - but both seem to fail to get the required dataset data from the project_datasets table.</p>
  
  <p>I have tried numerous combintations - but obviously not the right one.  </p>
  
  <p>For example, if I try putting function in Controller:</p>
  
  <pre><code>$this-&gt;set('projectDataset', $this-&gt;ProjectDataset-&gt;read(null, $id));
  $filename = $this-&gt;projectDataset['dataset_filename'];
  </code></pre>
  
  <p>fails - saying the SQL is incorrect (does not even look like sql!)</p>
  
  <p>and this:</p>
  
  <pre><code>$this-&gt;set('project_dataset', = $this-&gt;ProjectDataset-&gt;find('first',array('conditions' =&gt; array('id' =&gt; $id)));
          $filename = $this-&gt;project_dataset['dataset_filename'];
  </code></pre>
  
  <p>Fails reporting a SQL error.</p>
  
  <p>While if I put function in Model, then I get errors saying the object does not exist..</p>
  
  <p>Sorry for length of this, but would appreciate either suggested changes, or if you know something works, please do give me an example.</p>
  
  <p>Thanks</p>