0

I have created a Basic Joomla Component with Component Creator in order to prepare every single files in less the 1 minute :D (I'm lazy, i know.)

I have one view default and one for form edit.

I need to extend the class created by the Component Creator.

I have this controller.php

defined('_JEXEC') or die;

jimport('joomla.application.component.controller');

use \Joomla\CMS\Factory;

/**
 * Class Doclf_usersController
 *
 * @since  1.6
 */
class Doclf_usersController extends \Joomla\CMS\MVC\Controller\BaseController
{
    /**
     * Method to display a view.
     *
     * @param   boolean $cachable  If true, the view output will be cached
     * @param   mixed   $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
     *
     * @return  JController   This object to support chaining.
     *
     * @since    1.5
     * @throws Exception
     */
    public function display($cachable = false, $urlparams = false)
    {
        $app  = Factory::getApplication();
        $view = $app->input->getCmd('view', 'iscrizionelavoratoris');
        $app->input->set('view', $view);

        parent::display($cachable, $urlparams);

        return $this;
    }

Now i need to extend this class with my custom class, something like this

class DivStyle extends Doclf_usersController  {

    private $GetElementRisultato = "document.getElementById('risultato')";
    private $StyleColor = '.style.color =';
    private $Color = '"red"'

}

Unfortunately, it doesn't work... I tried also extends \Joomla\CMS\MVC\Controller\BaseControllerbut no win.... Error is

0 syntax error, unexpected 'class' (T_CLASS), expecting function (T_FUNCTION) or const (T_CONST)

How can i add my new class extend?

Thanks in advance for your help :)

UPDATED CODE BUT STILL DOESN'T WORK :(

    defined('_JEXEC') or die;

jimport('joomla.application.component.controller');

use \Joomla\CMS\Factory;

/**
 * Class Doclf_usersController
 *
 * @since  1.6
 */class Doclf_usersController extends \Joomla\CMS\MVC\Controller\BaseController
{
    /**
     * Method to display a view.
     *
     * @param   boolean $cachable  If true, the view output will be cached
     * @param   mixed   $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
     *
     * @return  JController   This object to support chaining.
     *
     * @since    1.5
     * @throws Exception
     */
    public function display($cachable = false, $urlparams = false)
    {
        $app  = Factory::getApplication();
        $view = $app->input->getCmd('view', 'iscrizionelavoratoris');
        $app->input->set('view', $view);

        parent::display($cachable, $urlparams);

        return $this;
    }

    class DivStyle extends Doclf_usersController {

        private $GetElementRisultato = "document.getElementById('risultato')";
        private $StyleColor = '.style.color =';
        private $Color = '"red"';
    }

    public function checkcodicefiscale() {
        $cf = new CodiceFiscale();
        $app = Factory::getApplication();   
        $input = $app->input;

        $cf ->SetCF($input->get('codice_fiscale', '')); 

        if ($input->exists('codice_fiscale')) {
            if ($cf->GetCodiceValido()) { 
                //Il codice fiscale è valido, procedo a verificare se esiste nel database
                $db = JFactory::getDbo();
                $query = "SELECT * FROM #__users_dati_anagrafici WHERE cf = '".$input->get('codice_fiscale')."'";
                $result = $db->setQuery($query)->loadObject();

                if ($result >0) {
                    //il codice fiscale esiste, pertanto procedo a bloccare il form
                    echo 'esiste';
                } else {

                }
                //  if($result != null)
                //  {$urlfile = $result->file;}
                //  else
                //  {}

                echo '<script>
                document.getElementById("risultato").style.color = "green";
                document.getElementById("bar_inizio").classList.remove(\'active\');
                document.getElementById("bar_inizio").classList.add(\'done\');
                </script>';

                echo 'Il Codice Fiscale è valido';

                //return valido

                jexit();
            } else {
                echo '<script>
                document.getElementById("risultato").style.color = "red";
                </script>';
                print $cf->GetErrore();
                jexit();
            }


            jexit();
        } else {

        jexit();
        }


    }





}
| improve this question | | | | |
New contributor
Andrea Suriani is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0

From the error it looks like you're placing the child class within the parent class like so:

class Doclf_usersController extends \Joomla\CMS\MVC\Controller\BaseController
{
    class DivStyle extends Doclf_usersController
    {
    }
}

But it should be outside and, ideally, in a separate file.

If you want to keep both classes in the same file for some reason, it should be like this:

class Doclf_usersController extends \Joomla\CMS\MVC\Controller\BaseController
{
    // Parent class code.
}

class DivStyle extends Doclf_usersController
{
    // Child class code.
}
| improve this answer | | | | |
  • THanks for your reply @Sharky but it seems doesn't work. I return the same error 0 syntax error, unexpected 'class' (T_CLASS), expecting function (T_FUNCTION) or const (T_CONST) – Andrea Suriani May 20 at 7:29
  • Post your updated code. – Sharky May 20 at 7:34
  • Done! It's at the end of the question – Andrea Suriani May 20 at 7:42
  • Your child class is still inside the parent class. I have updated the answer to clarify how to do this. Child class has to be on the same level as parent class, not enclosed in any braces. – Sharky May 20 at 7:57
  • Thanks! But now i have another problem because in the main class i'm call it from task for Ajax request. But let me do some test before update. Thanks for now! – Andrea Suriani May 20 at 8:15

Your Answer

Andrea Suriani is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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