1

I am trying to make a music component for Joomla 4

On the backend, my other forms work fine and the data is stored correctly in the database ( celebrity , album , etc...)

In the music form, when I click on the save and exit button, I get an error 500 Layout default not found. but the information is saved well in the database.

The codes used to display the forms are almost similar to each other and all the forms work correctly in the backend, but the music form has an error.

The code used in com_myext/admin/views/music/view.html.php file for music

defined('_JEXEC') or die('Restricted Access');

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\CMS\Helper\ContentHelper;

class AvisamusicdbViewMusic extends HtmlView
{
    protected $item;
    protected $form;

    public function display($tpl = null)
    {
        $this->item = $this->get('Item');
        $this->form = $this->get('Form');

        if (count($errors = $this->get('Errors'))) {
            throw new \Exception(implode('<br>', $errors), 500);
        }

        $this->addToolbar();

        return parent::display($tpl);
    }

    protected function addToolbar()
    {
        $input = Factory::getApplication()->input;
        $input->set('hidemainmenu', true);

        $user = Factory::getUser();
        $userId = $user->id;
        $isNew = $this->item->id == 0;
        $canDo = ContentHelper::getActions('com_avisamusicdb', 'component');

        ToolbarHelper::title(sprintf('%s: %s', Text::_('COM_AVISAMUSICDB'), Text::_('COM_AVISAMUSICDB_TITLE_MUSICS_EDIT')), '');

        if ($canDo->get('core.edit')) {
            ToolbarHelper::apply('music.apply', 'JTOOLBAR_APPLY');
            ToolbarHelper::save('music.save', 'JTOOLBAR_SAVE');
            ToolbarHelper::save2new('music.save2new');
            ToolbarHelper::save2copy('music.save2copy');
        }

        ToolbarHelper::cancel('music.cancel', 'JTOOLBAR_CLOSE');
    }
}

The code used in com_myext/admin/views/musics/view.html.php file for musics

defined('_JEXEC') or die('Restricted Access');

use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;

class AvisamusicdbViewMusics extends HtmlView
{
    protected $items;
    protected $state;
    protected $pagination;
    protected $model;
    public $filterForm, $activeFilters;
public function display($tpl = null)
    {
        $this->items            = $this->get('Items');
        $this->state            = $this->get('State');
        $this->pagination       = $this->get('Pagination');
        $this->model            = $this->getModel('musics');
        $this->filterForm       = $this->get('FilterForm');
        $this->activeFilters    = $this->get('ActiveFilters');


        if (count($errors = $this->get('Errors'))) {
            throw new \Exception(implode('<br>', $errors), 500);
        }

        AvisamusicdbHelper::addSubmenu('musics');
        $this->sidebar = JHtmlSidebar::render();

        $this->addToolbar();
        return parent::display($tpl);
    }
protected function addToolbar()
    {
        $state  = $this->get('State');
        $canDo  = ContentHelper::getActions('com_avisamusicdb', 'component');
        $user   = Factory::getUser();
        $bar    = Toolbar::getInstance('toolbar');

        if ($canDo->get('core.create')) {
            ToolbarHelper::addNew('music.add');
        }

        if ($canDo->get('core.edit')) {
            ToolbarHelper::editList('music.edit');
        }

        if ($canDo->get('core.edit.state')) {
            ToolbarHelper::publish('musics.publish', 'JTOOLBAR_PUBLISH', true);
            ToolbarHelper::unpublish('musics.unpublish', 'JTOOLBAR_UNPUBLISH', true);
            ToolbarHelper::archiveList('musics.archive');
            ToolbarHelper::checkin('musics.checkin');
        }
if ($state->get('filter.published') == -2 && $canDo->get('core.delete')) {
            ToolbarHelper::deleteList('', 'musics.delete', 'JTOOLBAR_EMPTY_TRASH');
        } elseif ($canDo->get('core.edit.state')) {
            ToolbarHelper::trash('musics.trash');
        }

        if ($canDo->get('core.admin')) {
            ToolbarHelper::preferences('com_avisamusicdb');
        }

        JHtmlSidebar::setAction('index.php?option=com_avisamusicdb&view=musics');
        ToolbarHelper::title(sprintf('%s: %s', Text::_('COM_AVISAMUSICDB'), Text::_('COM_AVISAMUSICDB_TITLE_MUSICS')), '');
    }
}

The structure of my folders and files is as follows i upload celebrity & celebrities for example for better understanding ( celebrities code , something like musics code )

enter image description here

admin\views\music\tmpl\edit.php code

<form action="<?php echo Route::_('index.php?option=com_avisamusicdb&view=music&layout=edit&id=' . (int) $this->item->id); ?>" name="adminForm" id="adminForm" method="post" class="form-validate">
    <?php if (JVERSION < 4 && !empty($this->sidebar)) { ?>
        <div id="j-sidebar-container" class="<?php echo $colClass; ?>2">
            <?php echo $this->sidebar; ?>
        </div>
        <div id="j-main-container" class="<?php echo $colClass; ?>10">
        <?php } else { ?>
            <div id="j-main-container"></div>
        <?php } ?>
        <div class="form-horizontal">
            <div class="<?php echo $rowClass; ?>">
                <div class="<?php echo $colClass; ?>12">
                    <?php echo HTMLHelper::_("$tab.startTabSet", 'myTab', array('active' => 'basic_configuration')); ?>
                    <?php echo HTMLHelper::_("$tab.addTab", 'myTab', 'basic_configuration', Text::_('COM_AVISAMUSICDB_FIELDSET_BASIC_INFO')); ?>
                    <?php echo $this->form->renderFieldset('basic_configuration'); ?>
                    <?php echo HTMLHelper::_("$tab.endTab"); ?>

                    <?php echo HTMLHelper::_("$tab.addTab", 'myTab', 'music_links', Text::_('COM_AVISAMUSICDB_FIELDSET_MUSIC_LINKS')); ?>
                    <?php echo $this->form->renderFieldset('music_links'); ?>
                    <?php echo HTMLHelper::_("$tab.endTab"); ?>

                    <?php echo HTMLHelper::_("$tab.addTab", 'myTab', 'music_trailers', Text::_('COM_AVISAMUSICDB_FIELDSET_MUSIC_TRAILER_URLS')); ?>
                    <?php echo $this->form->renderFieldset('music_trailers'); ?>
                    <?php echo HTMLHelper::_("$tab.endTab"); ?>

                    <?php echo HTMLHelper::_("$tab.endTabSet"); ?>
                </div>
            </div>
        </div>
        <input type="hidden" name="task" value="music.edit" />
        <?php echo HTMLHelper::_('form.token'); ?>
        </div>
</form>
21
  • This problem often occurs when the folder or files names are not spelled correctly. I am referring in particular to the upper and lower case of the words. Commented Jan 26, 2023 at 19:58
  • Can you turn of Debug On and Error messages to Maximum and the output should provide you more details about where the error is coming from and the stack trace of of calls that got you to the error.
    – Irata
    Commented Jan 26, 2023 at 22:54
  • @Irata my error on maximum and no any error... Commented Jan 26, 2023 at 23:34
  • @Gratia-Mira i upload pic from my files here you can all my folder correct all with lower case i never use file and folder name on upper case for my component Commented Jan 26, 2023 at 23:35
  • When you press Save & Close the processing is going to your controller /music and the data is being saved so things are working to that point from what you have written. From your controller you are then trying to do some form of redirect back to the list view in /music . What do you have in your controller/music.php where you are handling the return to the List view?
    – Irata
    Commented Jan 27, 2023 at 23:39

1 Answer 1

0

If your Save & Exit is supposed to bring you back to a list of records, views/musics, then the stack trace is showing you are trying to load a views/music, the singular or edit form view. Thus it is finding view/music/tmpl/edit.php and not views/musics/tmpl/default.php. Somewhere in your code you have a reference to music and not musics.

In your com_myext/admin/controllers/music.php you probably have reference to set the List view that is to be displayed once the music form is closed.

This is a sample that comes from a Joomla extension generator.

public function __construct()
{
    $this->view_list = 'musics';
    parent::__construct();
}

However if you change the musics to music then it will produce the same error message you seeing.

public function __construct()
{
    $this->view_list = 'music';
    parent::__construct();
}

$this-view_list is expecting a List view and you are providing an edit/form view.

3
  • i added this $this->view_list = 'musics'; to my com_myext/admin/controllers/music.php and after i use save and close i dont receive error but i have 1 question ( In all my code i have not any code about view_list ) in all my controller i have this code public function __construct($config = array()){parent::__construct($config);} all my component part work !!! why just music dont work ? Commented Jan 31, 2023 at 0:57
  • That is just one approach to setting the value for the list view. In your code somewhere is another approach that is setting a value of 'music' instead of 'musics'. You could compare a working example like celebrity with your music and look for somewhere you have used 'celebrities'(plural) in one and 'music'(singular) in the one not working. I would start with your controllers/music.php. If you still can't find it then do as @TerryCarter suggests and put a copy of your code somewhere it can viewed by people to help you or paste up the contents controllers/musics.php
    – Irata
    Commented Jan 31, 2023 at 1:20
  • tonight i try check all my code. if i dont find it, i share all my code and put link here, after joomla 4, i see many people beg other developer update music collection , or music download or try find some good music component for joomla 4, so i desicion make some free music component and after finish it give to all people want it as free. so then i upload it in git and other people can help for update it free for all... Commented Jan 31, 2023 at 1:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.