Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new folder into of controller is possible? #56

Closed
devnaelson opened this issue Mar 9, 2020 · 4 comments
Closed

new folder into of controller is possible? #56

devnaelson opened this issue Mar 9, 2020 · 4 comments

Comments

@devnaelson
Copy link

devnaelson commented Mar 9, 2020

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
Copy link
Author

devnaelson commented Mar 9, 2020

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();
    }`

@panique
Copy link
Owner

panique commented Mar 12, 2020

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!

@devnaelson
Copy link
Author

devnaelson commented Mar 12, 2020

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.

@wfsdaj
Copy link

wfsdaj commented Jul 11, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants