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

Discussion and education for beginner / novice programmers interested in embarking on the development process to take advantage of the extensible nature of the Joomla! CMS.

Moderators: tjay, seadap, Rogue4ngel, matthewhayashida

Forum rules
Post Reply
cjcj01
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Fri Nov 23, 2007 3:16 pm

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

Post by cjcj01 » Mon Jan 14, 2008 3:30 pm

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

cjcj01
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Fri Nov 23, 2007 3:16 pm

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

Post by cjcj01 » Tue Jan 15, 2008 10:56 am

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!


Post Reply