douzhang1926 2015-03-09 21:19
浏览 13
已采纳

如何更新joomla模块或后端中的表?

I working on some module and want to have ability to update table with image sizes - there already two columns in table (width, height). Its my first approach to joomla module develop. All code works except last foreach with update. Where I'm wrong?

And how to trigger this function in module or in backend module settings to button or link? Code in helper.php:

        public static function updateSize( $params )
{
        $app = JFactory::getApplication();
        $doc = JFactory::getDocument();
        JHtml::_('behavior.framework', true);
        $db = JFactory::getDbo();

        $query = $db->getQuery(true)
                        ->select($db->quoteName(array('a.imgfilename', 'b.catpath')))
                        ->from($db->quoteName('#__imagestable', 'a'))
                        ->where(($db->quoteName('height').'=') && ($db->quoteName('width').'='))
                        ->join('INNER', $db->quoteName('#__imagestable_cat', 'b') . ' ON (' . $db->quoteName('a.catid') . ' = ' . $db->quoteName('b.cid') . ')')
                        ->order('RAND() LIMIT 5');

        $db->setQuery($query);
        $size = $db->loadObjectList();
        return $size;

        foreach($size as $imageSize){
            $imgpath = $path.$imageSize->catpath.'/'.$imageSize->imgfilename;
            $imgfilename = $imageSize->imgfilename;
            list($width, $height) = getimagesize($imgpath);
            $validImgs[] = $imageSize;

            foreach ( $validImgs as $row ) {
                    $query = $db->getQuery(true)
                                 ->update($db->quoteName('#__imagestable')) 
                                 ->where ($db->quoteName('imgfilename').'='.$imgfilename)
                                 ->set(array($db->quoteName('height') . '=' . $height, $db->quoteName('width') . '=' .$width));

                     $db->setQuery($query); 
                     $imgSize = $db->execute();
                }
        }
}

Is it possible to attach this function to backend XML - maybe to button "Update image sizes"?

  • 写回答

1条回答 默认 最新

  • dongquming3255 2015-03-10 04:38
    关注

    You are using return $size; before the foreach.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?