mini3 icon indicating copy to clipboard operation
mini3 copied to clipboard

new folder into of controller is possible?

Open devnaelson opened this issue 4 years ago • 4 comments

I not got call a new folder into of controller folder and use. I will tries put it when me have time or whether you could make it

devnaelson avatar Mar 09 '20 12:03 devnaelson

Fast Optionaly solution while not have one another at moment

Folder Controller/Authserver/TestController.PHP

<?php
namespace Mini\Controller\Authserver;

class TestController
{
    public function index()
    {
       echo "Hello";
    }
}

config.php define('NEW_FOLDER', array('Authserver'));

` } elseif (!empty($this->url_controller)) {

        $amountFolders = count(NEW_FOLDER); // addicional folders

        $checkFileStep0 = file_exists(APP . 'Controller/' . ucfirst($this->url_controller) . 'Controller.php');

        if ($checkFileStep0 === false) {

            for ($i = 0; $i < count(NEW_FOLDER); $i++) {

                $checkFileStep1 = file_exists(APP . 'Controller/' . ucfirst(NEW_FOLDER[$i]) . '/' . ucfirst($this->url_controller) . 'Controller.php');

                if ($checkFileStep1 === true) {

                    //path
                    $controller = "\\Mini\\Controller\\" . ucfirst(NEW_FOLDER[$i]) . "\\" . ucfirst($this->url_controller) . 'Controller';

                    $this->url_controller = new $controller();

                    if (method_exists($this->url_controller, $this->url_action) && is_callable(array($this->url_controller, $this->url_action))) {

                        if (!empty($this->url_params)) {

                            call_user_func_array(array($this->url_controller, $this->url_action), $this->url_params);
                        } else {

                            $this->url_controller->{$this->url_action}();
                        }

                    } else {
                        if (strlen($this->url_action) == 0) {

                            $this->url_controller->index();
                        } else {
                            $page = new \Mini\Controller\ErrorController();
                            $page->index();
                        }
                    }
                }
            }

        } else {

            // here we did check for controller: does such a controller exist ?

            // if so, then load this file and create this controller
            // like \Mini\Controller\CarController
            $controller = "\\Mini\\Controller\\" . ucfirst($this->url_controller) . 'Controller';

            $this->url_controller = new $controller();

            // check for method: does such a method exist in the controller ?
            if (method_exists($this->url_controller, $this->url_action) && is_callable(array($this->url_controller, $this->url_action))) {

                if (!empty($this->url_params)) {
                    // Call the method and pass arguments to it
                    call_user_func_array(array($this->url_controller, $this->url_action), $this->url_params);
                } else {
                    // If no parameters are given, just call the method without parameters, like $this->home->method();
                    $this->url_controller->{$this->url_action}();
                }

            } else {
                if (strlen($this->url_action) == 0) {
                    // no action defined: call the default index() method of a selected controller
                    $this->url_controller->index();
                } else {
                    $page = new \Mini\Controller\ErrorController();
                    $page->index();
                }
            }
        }

    } else {

        $page = new \Mini\Controller\ErrorController();
        $page->index();
    }`

devnaelson avatar Mar 09 '20 15:03 devnaelson

I not got call a new folder into of controller folder and use. I will tries put it when me have time or whether you could make it

Hi, sorry but I dont understand the problem!

panique avatar Mar 12 '20 11:03 panique

I not got call a new folder into of controller folder and use. I will tries put it when me have time or whether you could make it

Hi, sorry but I dont understand the problem!

Not's problem! I was trying create new folders into of controller folder, but not work and then i did this and create my own method simple for add it.

devnaelson avatar Mar 12 '20 11:03 devnaelson

Fast Optionaly solution while not have one another at moment

Folder Controller/Authserver/TestController.PHP

<?php
namespace Mini\Controller\Authserver;

class TestController
{
    public function index()
    {
       echo "Hello";
    }
}

config.php define('NEW_FOLDER', array('Authserver'));

` } elseif (!empty($this->url_controller)) {

        $amountFolders = count(NEW_FOLDER); // addicional folders

        $checkFileStep0 = file_exists(APP . 'Controller/' . ucfirst($this->url_controller) . 'Controller.php');

        if ($checkFileStep0 === false) {

            for ($i = 0; $i < count(NEW_FOLDER); $i++) {

                $checkFileStep1 = file_exists(APP . 'Controller/' . ucfirst(NEW_FOLDER[$i]) . '/' . ucfirst($this->url_controller) . 'Controller.php');

                if ($checkFileStep1 === true) {

                    //path
                    $controller = "\\Mini\\Controller\\" . ucfirst(NEW_FOLDER[$i]) . "\\" . ucfirst($this->url_controller) . 'Controller';

                    $this->url_controller = new $controller();

                    if (method_exists($this->url_controller, $this->url_action) && is_callable(array($this->url_controller, $this->url_action))) {

                        if (!empty($this->url_params)) {

                            call_user_func_array(array($this->url_controller, $this->url_action), $this->url_params);
                        } else {

                            $this->url_controller->{$this->url_action}();
                        }

                    } else {
                        if (strlen($this->url_action) == 0) {

                            $this->url_controller->index();
                        } else {
                            $page = new \Mini\Controller\ErrorController();
                            $page->index();
                        }
                    }
                }
            }

        } else {

            // here we did check for controller: does such a controller exist ?

            // if so, then load this file and create this controller
            // like \Mini\Controller\CarController
            $controller = "\\Mini\\Controller\\" . ucfirst($this->url_controller) . 'Controller';

            $this->url_controller = new $controller();

            // check for method: does such a method exist in the controller ?
            if (method_exists($this->url_controller, $this->url_action) && is_callable(array($this->url_controller, $this->url_action))) {

                if (!empty($this->url_params)) {
                    // Call the method and pass arguments to it
                    call_user_func_array(array($this->url_controller, $this->url_action), $this->url_params);
                } else {
                    // If no parameters are given, just call the method without parameters, like $this->home->method();
                    $this->url_controller->{$this->url_action}();
                }

            } else {
                if (strlen($this->url_action) == 0) {
                    // no action defined: call the default index() method of a selected controller
                    $this->url_controller->index();
                } else {
                    $page = new \Mini\Controller\ErrorController();
                    $page->index();
                }
            }
        }

    } else {

        $page = new \Mini\Controller\ErrorController();
        $page->index();
    }`

Hello, do you have the complete code? I referred to your code and did not implement the corresponding function. Thank you.

wfsdaj avatar Jul 11 '23 07:07 wfsdaj