在Joomla框架的单个Article中添加多个带WYSIWYG编辑器的textarea

 

关键点:Joomla框架也是基于MVC架构模式的,所以在添加代码时应注意到这三个层次。因为已经有了一个带WYSIWYG编辑器的textarea,所以只需找到对应代码,按照相关代码进行添加。本人在添加代码时忽略了Controller这一层,导致带有链接或图片的内容一直不能完全显示。感谢James帮我解决了这一问题。

本次添加到的是proposal,以此为例:

1、依次找:components->com_content->views->article->tmpl文件夹,对proposal.php进行修改

依葫芦画瓢在原有代码

<?php echo $this->editor->save( 'text' ); ?>

下添加代码:

<?php echo $this->editor->save( 'refAndCitations' );

 

在原有代码

echo  ' &nbsp;<strong>Executive Summary:</strong><br />' . $this->editor->display('text', $this->article->text, '100%', '400', '70', '15');

下添加代码:

echo  '<br/><br/> &nbsp;<strong>References and Citations:</strong><br />' . $this->editor->display( 'refAndCitations',  $this->article->refAndCitations, '100%', '400', '70', '15');

这样proposal下面就会多了一个名为References and CitationsWYSIWYG编辑器。

 

2、依次找components->com_content->models文件夹,对article.php文件进行修改:

在原有代码:

$article->text= '';

下添加代码:$article->refAndCitations='';

另一处需要修改的地方是

store($data)函数里的添加:

$refAndCitations=$data['refAndCitations'];//this is about References and Citations

       if ($isNew)

       {

           $this->_id = $article->_db->insertId();      

          

           $query = 'INSERT INTO #__content_prosref (ref,content_id)' .

                     ' VALUES ( /''.$refAndCitations.'/','.(int) $this->_id.')';

           $this->_db->setQuery($query);

      

           if (!$this->_db->query()) {

              JError::raiseError( 500, $this->_db->stderr());

           }  

       }

       else{

           $query = 'UPDATE #__content_prosref SET ref=/'' .

                      $refAndCitations.'/'WHERE content_id='.(int) $this->_id.';';

           $this->_db->setQuery($query);

           if (!$this->_db->query()) {

              JError::raiseError( 500, $this->_db->stderr());

           }

       }

model层添加完毕,需注意还须在数据库中添加相应表。此表需三个字段(IDREF(MEDIUMTEXT)ARTICALID

 

3、在controller下须有一处修改:

components文件夹下的controller.php文件进行修改

在代码

$post['text'] = JRequest::getVar('text', '', 'post', 'string', JREQUEST_ALLOWRAW);

下面添加代码:

$post['refAndCitations'] = JRequest::getVar('refAndCitations', '', 'post', 'string', JREQUEST_ALLOWRAW);

 

现在可以把数据存入数据库,接下来完成取出、并显示该数据

4、依次找:modules->mod_filedisplay文件夹下的helper.php文件

添加代码:

function getRefAndCitations($articleId)

    {

       $db =& JFactory::getDBO();

       $sql = 'SELECT ref' .

              ' FROM #__content_prosref' .

              ' WHERE content_id = '.$articleId;

       $db->setQuery($sql);

       $db->query();

       $refAndCitations = $db->loadResultarray();

       if($refAndCitations != null && $refAndCitations!= "")

       {

           return $refAndCitations[0];

       }

       else

       {

           return $refAndCitations = false;

       }

    }

 

 

依次找:components->com_content->views->article->tmpl文件夹,对proposalshow.php进行修改:

在代码段:

<tr>

        <td height="43" colspan="2" style="border-bottom:1px solid #E0E0F9;" >

            <div style=" height:100px; height:auto !important;min-height:100px; overflow:visible; padding:5px;">

            <strong>Executive Summary:</strong><br/>

           <?php echo $this->article->text; ?>

            </div>

          </td>

      </tr>

下面添加如下代码:

        <tr>

            <td height="43" colspan="2" style="border-bottom:1px solid #E0E0F9;" >

            <div style=" height:100px; height:auto !important;min-height:100px; overflow:visible; padding:5px;">

            <strong>References and Citations: </strong><br/>

           <?php echo $this->params->get('refAndCitations');?>

            </div>           

            </td>

      </tr>

 

至此在Joomla框架的单个Article中添加多个带WYSIWYG编辑器的textarea完成。在此过程中,我遇到了很多困难,感谢JamesSlingna的耐心帮助。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值