【问题标题】:Component View displaying with 500 Internal Server Error显示 500 内部服务器错误的组件视图
【发布时间】:2012-10-07 09:46:10
【问题描述】:

我在学习 Joomla 组件开发教程时遇到问题。我遵循的与该问题相关的教程是thisthis

我可以正常查看默认视图,但是当我单击 neweditdelete 按钮时,或者当我也浏览 ../administrator/index.php?option=com_testimonials&view=testimonial&layout=edit 时,我会收到该错误。

我已经重新检查了很多次代码,但我就是找不到哪里出错了。

文件:controllers\testimonial.php

class TestimonialsControllerTestimonial extends JControllerForm
{
    //Nothing yet as per the tutorial
}

文件: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;
    }
}

文件: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'));
    }
}

文件: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>

【问题讨论】:

  • 只显示组件的一个原因是您的 url 可能有 tmpl=component。
  • @Irfan,这是我解决的命名问题,我已将问题更改为真正的问题。很抱歉造成混乱。

标签: joomla joomla2.5


【解决方案1】:

问题出在您的视图文件夹名称中。更改 testimonials folder name to testimonial,因为您已指定 view=testimonial。

如果它不起作用,请告诉我。

更新: 正如所讨论的那样,您的表存在命名问题-

class TestimonialsTableTestimonial extends JTable 
{ 
public function __construct(&$db) { 
parent::__construct('#__testimonial_table', 'id', $db); 
} 

function bind($array, $ignore = '') 
{ 

return parent::bind($array, $ignore); 
} 

}

【讨论】:

  • 对不起,这也是错字。其实我也有另一个视图testimonials,也就是设置为默认视图。
  • @mrN:你现在遇到了什么错误?检查你的控制器/testimonial.php
  • 我浏览时出现 500 内部服务器错误 ../administrator/index.php?option=com_testimonials&view=testimonial&layout=edit
  • @mrN: 如果你能用路径发布你的控制器和模型代码,那就太好了。
  • @mrN:一旦看起来有问题的是 getTable($type = 'Testimonials' 将其更改为 - getTable($type = 'Testimonial' 并检查表/testimonial.php
猜你喜欢
  • 2013-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-29
  • 2020-11-28
相关资源
最近更新 更多