关键点: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 ' <strong>Executive Summary:</strong><br />' . $this->editor->display('text', $this->article->text, '100%', '400', '70', '15');
下添加代码:
echo '<br/><br/> <strong>References and Citations:</strong><br />' . $this->editor->display( 'refAndCitations', $this->article->refAndCitations, '100%', '400', '70', '15');
这样proposal下面就会多了一个名为References and Citations的WYSIWYG编辑器。
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层添加完毕,需注意还须在数据库中添加相应表。此表需三个字段(ID,REF(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完成。在此过程中,我遇到了很多困难,感谢James和Slingna的耐心帮助。