问题
I have having issues following the tutorial of component development of Joomla. The tutorials I followed related to the issue are this and this.
I can view the default view properly, but when I click the new
or edit
and delete
button, or when I browse too ../administrator/index.php?option=com_testimonials&view=testimonial&layout=edit
I get that error.
I have rechecked the code so many times but I just can't find where I went wrong.
File: controllers\testimonial.php
class TestimonialsControllerTestimonial extends JControllerForm
{
//Nothing yet as per the tutorial
}
File: models\testimonial.php
class TestimonialsModelTestimonial extends JModelAdmin {
public function getTable($type = 'Testimonials', $prefix = 'TestimonialsTable', $config = array()) {
return JTable::getInstance($type, $prefix, $config);
}
public function getForm($data = array(), $loadData = true) {
// Get the form
$form = $this -> loadForm('com_testimonials.testimonial', 'testimonial', array('control' => 'jform', 'load_data' => $loadData));
if(empty($form)) {
return false;
}
return $form;
}
protected function loadFormData() {
// Check the session for previously entered form data
$data = JFactory::getApplication() -> getUserState('com_testimonials.edit.testimonial.data', array());
if(empty($data)) {
$data = $this -> getItem();
}
return $data;
}
}
File: views\testimonial\view.html.php
class TestimonialsViewTestimonial extends JView {
protected $form = null;
public function display($tpl = null) {
//get the data
$form = $this -> get('Form');
$item = $this -> get('Item');
$this -> form = $form;
$this -> item = $item;
$this -> addToolbar();
parent::display($tpl);
$this -> setDocument();
}
protected function addToolBar() {
JRequest::setVar('hidemainmenu', true);
$isNew = ($this -> item -> id == 0);
JToolBarHelper::title($isNew ? JText::_('COM_TESTIMONIALS_MANAGER_TESTIMONIAL_NEW') : JText::_('COM_TESTIMONIALS_MANAGER_TESTIMONIAL_EDIT'), 'testimonials');
JToolBarHelper::save('testimonial.save');
JToolBarHelper::cancel('testimonial.cancel', $isNew ? 'JTOOLBAR_CANCEL' : 'JTOOLBAR_CLOSE');
}
protected function setDocument() {
$isNew = ($this -> item -> id < 1);
$document = JFactory::getDocument();
$document -> setTitle($isNew ? JText::_('COM_TESTIMONIALS_TESTIMONIAL_CREATING') : JText::_('COM_TESTIMONIALS_TESTIMONIAL_EDITING'));
}
}
File: views\testimonial\tmpl\edit.php
<form action="<?php echo JRoute::_('index.php?option=com_testimonials&layout=edit&id='.(int) $this -> item -> id); ?>" method="post" name="adminForm" id="testimonial-form">
<fieldset class="adminForm">
<legend><?php echo JText::_('COM_TESTIMONIALS_TESTIMONIAL_DETAILS'); ?></legend>
<ul class="adminFormList">
<?php foreach($this -> form -> getFieldset() as $field): ?>
<li><?php echo $field -> label; echo $field -> input; ?></li>
<?php endforeach; ?>
</ul>
</fieldset>
<div>
<input type="hidden" name="task" value="testimonial.edit" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
回答1:
The problem is in your view folder name. Change testimonials folder name to testimonial
as you have specified view=testimonial.
let me know if it does not work.
Update: As discussed your table having naming problem-
class TestimonialsTableTestimonial extends JTable
{
public function __construct(&$db) {
parent::__construct('#__testimonial_table', 'id', $db);
}
function bind($array, $ignore = '')
{
return parent::bind($array, $ignore);
}
}
来源:https://stackoverflow.com/questions/12929169/component-view-displaying-with-500-internal-server-error