Jump to content

jaoman

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jaoman's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. TimeBomb, Bingo! That did it! Thanks a lot. And a huge thanks to everybody else who's posted.
  2. Yes, it does. The code is in another file. <?php // No direct access outside Joomla. defined ('_JEXEC') or die ('Restricted access'); // Includes the helper file require_once dirname(__FILE__).'/helper.php'; $thumbnail = ThumbnailHelper::get_thumbnail (); // Get the layout require JModuleHelper::getLayoutPath('mod_DT', $params->get('layout', 'default')); ?> $thumbnail then gets used by my view file to display the thumbnail. Unfortunately, this only seems to happen when my helper.php file doesn't rely on functions.
  3. Okay. Here's the full error I am getting: The full file looks like this: <?php /* * @author: Jaoman * @copyright (C) - Jaoman 2012 * * @package: mod_displaythumbnail * @file: helper.php * @purpose: This helper.php acts the Model for the mod_displaythumbnail module, providing logic support. * It connects to the VirtueMart framework, retrieves product data, parses data for image thumbnails location, * and returns the image. */ // No direct access outside Joomla. defined ('_JEXEC') or die ('Restricted access'); // Configures VirtueMart variables and stores them into cache. if (!class_exists( 'VmConfig' )) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart'.DS.'helpers'.DS.'config.php'); VmConfig::loadConfig(); // Loads the language file of com_virtuemart. JFactory::getLanguage()->load('com_virtuemart'); // Loads the VirtueMart image class. if (!class_exists( 'VmImage' )) require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart'.DS.'helpers'.DS.'image.php'); // Loads VirtueMart Models. if (!class_exists( 'VirtueMartModelProduct' )) { JLoader::import( 'product', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'models' ); } if (!class_exists ('VmModel')) require (JPATH_ADMINISTRATOR.DS.'helpers'.DS.'vmmodel.php'); // Loads VirtueMart category model. if (!class_exists( 'VirtueMartModelCategory' )) require(JPATH_VM_ADMINISTRATOR.DS.'models'.DS.'category.php'); class ThumbnailHelper { /* * @function: get_thumbnail * @description: Retrieves the thumbnail image of a random VirtueMart product * @param: None. * @return: String with html to display an image. */ function get_thumbnail () { $category_list = $this->get_categories(); $category = array_rand ($category_list); $random_product = $this->get_random_product ($category); $image = $random_product->images [0]->displayMediaThumb('class="product-image"', true, 'class="modal"', true, true); return $image; } /* * @function: get_random_product * @description: Retrieves a random product from a VM category. * @param: Category with at least one product. * @return: VM Product object. */ function get_random_product ($category) { $product_model = VmModel::getModel ('product'); $category_id = $category->virtuemart_category_id; $products = $product_model->getProductsInCategory ($category_id); $product_model->addImages ($products, 1); $product_population = count ($products); $random_product_key = rand (0, $product_population -1); return $products [$random_product_key]; } /* * @function: get_categories * @description: Retrieves an array of associative arrayss of the categories in VirtueMart. * @param: None. * @return: Array full of associative arrays. Keys are numbers. */ function get_categories () { // Returns the model object for VirtueMart categories. $category_model = VmModel::getModel ('category'); // Returns an array of category objects. Each object is an associative array. $category_list = $category_model->getCategories (); return $category_list; } } ?> You can't tell from here, but when you plug it into an editor, line 49 is "[]$category_list = $this->get_categories();[/i]". I know the code itself works because, when I remove the other functions and just run all of it out of get_thumbnail, the module executes without a hitch. Does anyone have an answer?
  4. That would make sense, wouldn't it. Here's the offensive code: class ThumbnailHelper { /* * @function: get_thumbnail * @description: Retrieves the thumbnail image of a random VirtueMart product * @param: None. * @return: String with html to display an image. */ function get_thumbnail () { $category_list = $this->get_categories(); // The offending line! $category = array_rand ($category_list); $random_product = $this->get_random_product ($category); $image = $random_product->images [0]->displayMediaThumb('class="product-image"', true, 'class="modal"', true, true); return $image; } /* * @function: get_random_product * @description: Retrieves a random product from a VM category. * @param: Category with at least one product. * @return: VM Product object. */ function get_random_product ($category) { $product_model = VmModel::getModel ('product'); $category_id = $category->virtuemart_category_id; $products = $product_model->getProductsInCategory ($category_id); $product_model->addImages ($products, 1); $product_population = count ($products); $random_product_key = rand (0, $product_population -1); return $products [$random_product_key]; } /* * @function: get_categories * @description: Retrieves an array of associative arrayss of the categories in VirtueMart. * @param: None. * @return: Array full of associative arrays. Keys are numbers. */ function get_categories () { $category_model = VmModel::getModel ('category'); $category_list = $category_model->getCategories (); return $category_list; } } Unless being inside a class has some different meaning in php than elsewhere, I am clearly inside the class brackets. Grrr.
  5. requinix, Thanks. I tried your suggestion, but now I get a different error: "Using $this when not in object context..." What does that mean?
  6. I teaching myself php, but I am coming from java and other compiled languages, so the process has been a little bumpy. I am trying to do something like this: class my_class { function one () { $two = two (); $three = three (); $five = $two + $three; return $five; } function two () { $two = 2; return $two; } function three () { $three = 3; return $three; } } Unfortunately, I keep getting an error message saying that my call to two () is an undefined function. I am gathering from this that the scope of one () is not aware of the existence of two (). Is there a way to get around this so I can call two () and three () from one ()?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.