500 View class not found [class, file]: #982

Closed
opened 2023-02-27 15:57:24 +00:00 by Alessandro · 8 comments

Steps to reproduce the issue

I just Upgrade JCB to 3.1.19 from 3.1.12, everything works fine during the installation and even while compiling an old project it works without error, but once I try to open a backend page of the compiled component I always get this error "500 View class not found [class, file]:"

Expected result

Open the backend the selected page of the component as always

Actual result

Instead I get a message "An error has occurred.", "500 View class not found [class, file]: [component name], [path to relative view.html.php]"

System information (as much as possible)

  • OS Name & Version: Kubuntu 22.04
  • MySql Version: 10.3.38-MariaDB-0+deb10u1
  • Apache Version: 2.4.38
  • PHP Version: 8.1.16
  • Joomla Version: 3.10.11
  • JCB Version: 3.1.19
  • Browser: Firefox 110.0

Additional comments

I tried even a different version and I have the same problem even with 3.1.17 and 3.1.15

### Steps to reproduce the issue I just Upgrade JCB to 3.1.19 from 3.1.12, everything works fine during the installation and even while compiling an old project it works without error, but once I try to open a backend page of the compiled component I always get this error "500 View class not found [class, file]:" ### Expected result Open the backend the selected page of the component as always ### Actual result Instead I get a message "An error has occurred.", "500 View class not found [class, file]: [component name], [path to relative view.html.php]" ### System information (as much as possible) - OS Name & Version: Kubuntu 22.04 - MySql Version: 10.3.38-MariaDB-0+deb10u1 - Apache Version: 2.4.38 - PHP Version: 8.1.16 - Joomla Version: 3.10.11 - JCB Version: 3.1.19 - Browser: Firefox 110.0 ### Additional comments I tried even a different version and I have the same problem even with 3.1.17 and 3.1.15
Owner

Please make sure to use PHP 7.4 (I know... its not good, but that is where we are, and so that is our first step to see what is the cause)

Second step see if the file that is said to be missing, is actually being build and added to the package.

Please note that I don't get this error, so unless you can guid me to duplicate this error, there is very little I can do to help you.

Please make sure to use PHP 7.4 (I know... its not good, but that is where we are, and so that is our first step to see what is the cause) Second step see if the file that is said to be missing, is actually being build and added to the package. Please note that I don't get this error, so unless you can guid me to duplicate this error, there is very little I can do to help you.
Author

First Step, I changed my PHP version to 7.4.33, recompile the component but I get the same result, so probably isn't a PHP version related.

Second step, the file is actually there but I can see something really strange, it seems like some part of the code hasn't been compiled.

Let me paste here the file content so I'm sure it will help you to understand what is happening. As you can see before "###BOM###" there is a "?>" that "close" the PHP so the error, and after that it seems code not completed/compiled.

* @github Joomla Component Builder * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access to this file defined('_JEXEC') or die('Restricted access'); ?>

###BOM###

// No direct access to this file
defined('_JEXEC') or die('Restricted access');

###DASH_VIEW_HTML_HEADER###

/**

  • ###Component### View class
    /
    class ###Component###View###Component### extends JViewLegacy
    {
    /
    *

    • View display method

    • @return void
      */
      function display($tpl = null)
      {
      // Assign data to the view
      $this->icons = $this->get('Icons');
      $this->contributors = ###Component###Helper::getContributors();###DASH_GET_CUSTOM_DATA###

      // get the manifest details of the component
      $this->manifest = ###Component###Helper::manifest();

      // Set the toolbar
      $this->addToolBar();

      // Check for errors.
      if (count($errors = $this->get('Errors')))
      {
      throw new Exception(implode("\n", $errors), 500);
      }

      // Display the template
      parent::display($tpl);

      // Set the document
      $this->setDocument();
      }

    /**

    • Setting the toolbar
      */
      protected function addToolBar()
      {
      $canDo = ###Component###Helper::getActions('###component###');
      JToolBarHelper::title(JText::('COM###COMPONENT###_DASHBOARD'), 'grid-2');

      // set help url for this view if found
      $this->help_url = ###Component###Helper::getHelpUrl('###component###');
      if (###Component###Helper::checkString($this->help_url))
      {
      JToolbarHelper::help('COM_###COMPONENT###_HELP_MANAGER', false, $this->help_url);
      }

      if ($canDo->get('core.admin') || $canDo->get('core.options'))
      {
      JToolBarHelper::preferences('com_###component###');
      }
      }

    /**

    • Method to set up the document properties

    • @return void
      */
      protected function setDocument()
      {
      $document = JFactory::getDocument();

      // add dashboard style sheets
      $document->addStyleSheet(JURI::root() . "administrator/components/com_###component###/assets/css/dashboard.css");

      // set page title
      $document->setTitle(JText::('COM###COMPONENT###_DASHBOARD'));

      // add manifest to page JavaScript
      $document->addScriptDeclaration("var manifest = jQuery.parseJSON('" . json_encode($this->manifest) . "');", "text/javascript");
      }
      }

First Step, I changed my PHP version to 7.4.33, recompile the component but I get the same result, so probably isn't a PHP version related. Second step, the file is actually there but I can see something really strange, it seems like some part of the code hasn't been compiled. Let me paste here the file content so I'm sure it will help you to understand what is happening. As you can see before "###BOM###" there is a "?>" that "close" the PHP so the error, and after that it seems code not completed/compiled. <?php /** * @package Joomla.Component.Builder * * @created 30th April, 2015 * @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com> * @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder> * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access to this file defined('_JEXEC') or die('Restricted access'); ?> ###BOM### // No direct access to this file defined('_JEXEC') or die('Restricted access'); ###DASH_VIEW_HTML_HEADER### /** * ###Component### View class */ class ###Component###View###Component### extends JViewLegacy { /** * View display method * @return void */ function display($tpl = null) { // Assign data to the view $this->icons = $this->get('Icons'); $this->contributors = ###Component###Helper::getContributors();###DASH_GET_CUSTOM_DATA### // get the manifest details of the component $this->manifest = ###Component###Helper::manifest(); // Set the toolbar $this->addToolBar(); // Check for errors. if (count($errors = $this->get('Errors'))) { throw new Exception(implode("\n", $errors), 500); } // Display the template parent::display($tpl); // Set the document $this->setDocument(); } /** * Setting the toolbar */ protected function addToolBar() { $canDo = ###Component###Helper::getActions('###component###'); JToolBarHelper::title(JText::_('COM_###COMPONENT###_DASHBOARD'), 'grid-2'); // set help url for this view if found $this->help_url = ###Component###Helper::getHelpUrl('###component###'); if (###Component###Helper::checkString($this->help_url)) { JToolbarHelper::help('COM_###COMPONENT###_HELP_MANAGER', false, $this->help_url); } if ($canDo->get('core.admin') || $canDo->get('core.options')) { JToolBarHelper::preferences('com_###component###'); } } /** * Method to set up the document properties * * @return void */ protected function setDocument() { $document = JFactory::getDocument(); // add dashboard style sheets $document->addStyleSheet(JURI::root() . "administrator/components/com_###component###/assets/css/dashboard.css"); // set page title $document->setTitle(JText::_('COM_###COMPONENT###_DASHBOARD')); // add manifest to page JavaScript $document->addScriptDeclaration("var manifest = jQuery.parseJSON('" . json_encode($this->manifest) . "');", "text/javascript"); } }
Author

Actually after I posted, I checked other problem listed and I saw a similar problem where a workaround has been suggested #978 (comment), actually the suggested change fixed my problem.

So it happens just when "Add Update Server" is set to "No", if I set it to "Yes" even leaving empty the field everything works as expected

Actually after I posted, I checked other problem listed and I saw a similar problem where a workaround has been suggested https://git.vdm.dev/joomla/Component-Builder/issues/978#issuecomment-19540, actually the suggested change fixed my problem. So it happens just when "Add Update Server" is set to "No", if I set it to "Yes" even leaving empty the field everything works as expected
Author

After I saw the problem was fixed using the workaround suggested, just to test I switch back to PHP 8.1.16 and everything still works as expected.

So I guess the good news is that PHP 8.1 shouldn't be a problem, but the problem persist and seems to be completely related with the field "Add Update Server" in some way.

Now I'll set back the system to PHP 7.4 until we are sure to be PHP 8 fully compatible.

After I saw the problem was fixed using the workaround suggested, just to test I switch back to PHP 8.1.16 and everything still works as expected. So I guess the good news is that PHP 8.1 shouldn't be a problem, but the problem persist and seems to be completely related with the field "Add Update Server" in some way. Now I'll set back the system to PHP 7.4 until we are sure to be PHP 8 fully compatible.
Member

I just updated JCB to 3.1.19 running on PHP 7.4 and had excatly the same problem as Alessandro. The component was generated normally, but after install and comparing the generated code, models and views code were not correctly generated. After setting the Add Update Server to Yes, everything works with just minor changes to the code (comments). Strange enough you can even set the Update Server back to No, but the field with the server must be filled - if you clear the Update Server field and set Add Update Server to No the error will return. Hth

I just updated JCB to 3.1.19 running on PHP 7.4 and had excatly the same problem as Alessandro. The component was generated normally, but after install and comparing the generated code, models and views code were not correctly generated. After setting the Add Update Server to Yes, everything works with just minor changes to the code (comments). Strange enough you can even set the Update Server back to No, but the field with the server must be filled - if you clear the Update Server field and set Add Update Server to No the error will return. Hth
Owner

I thought that I fixed #978 this... seems I need to do a little more.

Here you can see the code that was added in response to the issue.

Will you try the following? Just add the following lines:

// catch empty URL to update server TODO: we need to fix this in  better way later
if (empty($component->add_update_server) || ($component->add_update_server == 1 && $component->update_server_target !== 3
	&& (
		!StringHelper::check($component->update_server_url)
		|| strpos($component->update_server_url, 'http') === false
	)))
{
	// we fall back to other, since we can't work with an empty update server URL
	$component->add_update_server = 0;
	$component->update_server_target = 3;
	$component->update_server_url = '';
}

This should fix this issue.

I thought that I fixed [#978](https://git.vdm.dev/joomla/Component-Builder/issues/978) this... seems I need to do a little more. Here you can see the [code that was added](https://git.vdm.dev/joomla/Component-Builder/src/branch/staging/libraries/jcb_powers/VDM.Joomla/src/Componentbuilder/Compiler/Component/Data.php#L798-L808) in response to the issue. Will you try the following? Just add the following lines: ``` // catch empty URL to update server TODO: we need to fix this in better way later if (empty($component->add_update_server) || ($component->add_update_server == 1 && $component->update_server_target !== 3 && ( !StringHelper::check($component->update_server_url) || strpos($component->update_server_url, 'http') === false ))) { // we fall back to other, since we can't work with an empty update server URL $component->add_update_server = 0; $component->update_server_target = 3; $component->update_server_url = ''; } ``` This should fix this issue.
Member

Yes! that fixed the problem, compiled and installed a component not touched before. Thank you - great work.

Yes! that fixed the problem, compiled and installed a component not touched before. Thank you - great work.
Owner

I assume this is fixed.

I assume this is fixed.
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#982
No description provided.