Page 1 of 1

J!1.5 M-V-C - view.html... How to pass a variable back to a function in a model?

Posted: Mon Jan 14, 2008 3:30 pm
by cjcj01
Hi.  I'm trying to work my way through this M-V-C thing..

Basically, I've got a variable in com_mycomponent/views/mycomponent/tmpl/default.php

Which looks like this:

Code: Select all

$file = $fileRS->fields['filename']->value; 
 

It returns the filename of a document from an Indexing Server Catalog object.  And it works.

I want to pass $file back to a function in com_mycomponent/models/mycomponent.php

here's my function:

Code: Select all

function getDOCmanDocName($file)

    {
      $db =& JFactory::getDBO();

      $query = 'SELECT dmname AS text'

            . ' FROM #__docman'

            . ' WHERE dmfilename = ' . $file;

      $db->setQuery( $query );

      $docname = $db->loadResult();

      return $docname;

    }


I know I can echo $this->docname; in default.php thus calling the function getDOCmanDocName via view.html e.g. in view.html:

Code: Select all

$model =& $this->getModel();
$docname = $model->getDOCmanDocName();
$this->assignRef('docname', $docname);


But how do I pass back $file to the function?  I've tried: $this->docname($file) - but don't know if this is valid, and if it is, how do I edit view.html?

Would appreciate thoughts anyone.. thanks
chris

Re: J!1.5 M-V-C - view.html... How to pass a variable back to a function in a mo

Posted: Tue Jan 15, 2008 10:56 am
by cjcj01
ok -  :D I got my head all twisted.

I'm trying to do something in the template that should be done in the view!

I've restructured my code and all working. phew!