سلام دوستان
برای افزودن یک فیلد به صفحه مدیریت مطلب، به صورت زیر عمل کردم:
اول توی دیتابیس، در جدول xxxx_content، پس از کلیک روی structure، یک فرم و ردیف با نام دلخواه ساخته شد:
حال تنظیمات فایل ها در پوشه administrator:
ویرایش فایل administrator/components/com_content/views/article/tmpl/edit.php
<?php
// No direct access.
defined('_JEXEC') or die;
// Include the component HTML helpers.
JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');
// Load the tooltip behavior.
JHtml::_('behavior.tooltip');
JHtml::_('behavior.formvalidation');
JHtml::_('behavior.keepalive');
// Create shortcut to parameters.
$params = $this->state->get('params');
$params = $params->toArray();
// This checks if the config options have ever been saved. If they haven't they will fall back to the original settings.
$editoroptions = isset($params['show_publishing_options']);
if (!$editoroptions):
$params['show_publishing_options'] = '1';
$params['show_article_options'] = '1';
$params['show_urls_images_backend'] = '0';
$params['show_urls_images_frontend'] = '0';
endif;
// Check if the article uses configuration settings besides global. If so, use them.
if (!empty($this->item->attribs['show_publishing_options'])):
$params['show_publishing_options'] = $this->item->attribs['show_publishing_options'];
endif;
if (!empty($this->item->attribs['show_article_options'])):
$params['show_article_options'] = $this->item->attribs['show_article_options'];
endif;
if (!empty($this->item->attribs['show_urls_images_backend'])):
$params['show_urls_images_backend'] = $this->item->attribs['show_urls_images_backend'];
endif;
?>
<script type="text/javascript">
Joomla.submitbutton = function(task) {
if (task == 'article.cancel' || document.formvalidator.isValid(document.id('item-form'))) {
<?php echo $this->form->getField('articletext')->save(); ?>
Joomla.submitform(task, document.getElementById('item-form'));
} else {
alert('<?php echo $this->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));?>');
}
}
</script>
<form action="<?php echo JRoute::_('index.php?option=com_content&layout=edit&id='.(int) $this->item->id); ?>" method="post" name="adminForm" id="item-form" class="form-validate">
<div class="width-60 fltlft">
<fieldset class="adminform">
<legend><?php echo empty($this->item->id) ? JText::_('COM_CONTENT_NEW_ARTICLE') : JText::sprintf('COM_CONTENT_EDIT_ARTICLE', $this->item->id); ?></legend>
<ul class="adminformlist">
<li><?php echo $this->form->getLabel('title'); ?>
<?php echo $this->form->getInput('title'); ?></li>
[font=Verdana] [/font][color=#FF0000][font=Verdana] <li><?php echo $this->form->getLabel('supertitle2'); ?>[/font][/color]
[color=#ff0000][font=Verdana] <?php echo $this->form->getInput('supertitle2'); ?></li>[/font]
[/color]
(بقیه فایل رو در اینجا نیاوردم)
ویرایش فایل administrator/components/com_content/models/forms/article.xml
[/color]<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset addfieldpath="/administrator/components/com_categories/models/fields" >
<field name="id" type="text" class="readonly" label="JGLOBAL_FIELD_ID_LABEL"
description ="JGLOBAL_FIELD_ID_DESC" size="10" default="0"
readonly="true" />
<field name="asset_id" type="hidden" filter="unset" />
[color=#ff0000][font=Verdana] <field name="supertitle2" type="text" size="50" default="" label="Super title" [/font][/color][color=#FF0000][font=Verdana]description="" class="inputbox" />[/font][/color]
<field name="title" type="text" label="JGLOBAL_TITLE"
description="JFIELD_TITLE_DESC" class="inputbox" size="30"
required="true" />
<field name="alias" type="text" label="JFIELD_ALIAS_LABEL"
description="JFIELD_ALIAS_DESC" class="inputbox" size="45" />
<field name="articletext" type="editor" class="inputbox"
label="COM_CONTENT_FIELD_ARTICLETEXT_LABEL" description="COM_CONTENT_FIELD_ARTICLETEXT_DESC"
filter="JComponentHelper::filterText" buttons="true" />
<field name="state" type="list" label="JSTATUS"
description="JFIELD_PUBLISHED_DESC" class="inputbox"
filter="intval" size="1" default="1"
>
[color=#0000ff]
(ادامه فایل رو ذکر نکردم)
تا اینجا مقدار وارد شده در فیلد اضاف شده، با موفقیت وارد دیتابیس می شود:
حالا ی سوال داشتم، چطور می تونیم این مقدار رو در مطلب نمایش داد؟
فایل های زیر رو هم ویرایش کردم :
ویرایش فایل components/com_content/views/form/tmpl/edit.php
[/color]<?php
// no direct access
defined('_JEXEC') or die;
JHtml::_('behavior.keepalive');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.calendar');
JHtml::_('behavior.formvalidation');
// Create shortcut to parameters.
$params = $this->state->get('params');
//$images = json_decode($this->item->images);
//$urls = json_decode($this->item->urls);
// This checks if the editor config options have ever been saved. If they haven't they will fall back to the original settings.
$editoroptions = isset($params->show_publishing_options);
if (!$editoroptions):
$params->show_urls_images_frontend = '0';
endif;
?>
<script type="text/javascript">
Joomla.submitbutton = function(task) {
if (task == 'article.cancel' || document.formvalidator.isValid(document.id('adminForm'))) {
<?php echo $this->form->getField('articletext')->save(); ?>
Joomla.submitform(task);
} else {
alert('<?php echo $this->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED'));?>');
}
}
</script>
<div class="edit item-page<?php echo $this->pageclass_sfx; ?>">
<?php if ($params->get('show_page_heading')) : ?>
<h1>
<?php echo $this->escape($params->get('page_heading')); ?>
</h1>
<?php endif; ?>
<form action="<?php echo JRoute::_('index.php?option=com_content&a_id='.(int) $this->item->id); ?>" method="post" name="adminForm" id="adminForm" class="form-validate">
<fieldset>
<legend><?php echo JText::_('JEDITOR'); ?></legend>
<div class="formelm">
<?php echo $this->form->getLabel('title'); ?>
<?php echo $this->form->getInput('title'); ?>
<?php echo $this->form->getLabel('supertitle2'); ?>
<?php echo $this->form->getInput('supertitle2'); ?>
</div>
[color=#0000ff]
(بقیه کد رو ذکر نکردم)
ویرایش فایل components/com_content/views/article/tmpl/default.php
[/color]<?php
// no direct access
defined('_JEXEC') or die;
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers');
// Create shortcuts to some parameters.
$params = $this->item->params;
$images = json_decode($this->item->images);
$attrb = json_decode($this->item->attribs);
echo $attrb->mytextvalue;
$urls = json_decode($this->item->urls);
$canEdit = $this->item->params->get('access-edit');
$user = JFactory::getUser();
?>
<div class="item-page<?php echo $this->pageclass_sfx?>">
<?php if ($this->params->get('show_page_heading')) : ?>
<h1>
<?php echo $this->escape($this->params->get('page_heading')); ?>
</h1>
<?php endif; ?>
<?php
if (!empty($this->item->pagination) AND $this->item->pagination && !$this->item->paginationposition && $this->item->paginationrelative)
{
echo $this->item->pagination;
}
?>
<?php if ($params->get('show_title')) : ?>
<h2>
<?php if ($params->get('link_titles') && !empty($this->item->readmore_link)) : ?>
<a href="<?php echo $this->item->readmore_link; ?>">
<?php echo $this->escape($this->item->title); ?></a>
<?php else : ?>
<?php echo $this->escape($this->item->title); ?>
<?php endif; ?>
</h2>
<?php endif; ?>
<?php if ($params->get('show_title')) : ?>
<h2>
<?php if ($params->get('link_titles') && !empty($this->item->readmore_link)) : ?>
<a href="<?php echo $this->item->readmore_link; ?>">
<?php echo $this->escape($this->item->supertitle2); ?></a>
<?php else : ?>
<?php echo $this->escape($this->item->supertitle2); ?>
<?php endif; ?>
</h2>
<?php endif; ?>
[color=#0000ff]
(بقیه کدها ذکر نشده)
ویرایش فایل components/com_content/models/forms/article.xml
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset addfieldpath="/administrator/components/com_categories/models/fields">
<field
id="id"
name="id"
type="hidden"
class="inputbox"
label="COM_CONTENT_ID_LABEL"
size="10"
default="0"
readonly="true" />
<field
name="asset_id"
type="hidden"
filter="unset" />
<field
id="supertitle2"
name="supertitle2"
type="text"
class="inputbox"
size="30"
required="true" />
(بقیه کد ذکر نشده)
مشکل کجاست؟:jan: چرا مقدار وارد شده در فیلد مورد نظر در صفحه یک مطلب نمایش داده نمی شود؟!!! لطفا راهنمایی کنید.