Alto Router

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Donald Boers

Donald Boers

14/05/2015 11:53:21
Quote Anchor link
Ik heb een vraagje. Is er iemand bekend met Alto Router? Ik gebruik Alto Router voor het eerst maar krijg het niet voor elkaar om een underscore in mijn acties te gebruiken, b.v. double_roomAction.

Ik zou het zeer op prijs stellen als iemand me in de juiste richting kan helpen.Bij voorbaat dank
 
PHP hulp

PHP hulp

13/03/2025 01:34:12
 
Wouter Van Marrum

Wouter Van Marrum

14/05/2015 12:02:07
Quote Anchor link
Ja ik gebruik het ook toevallig.
Zo weet ik toevallig dat je # moet gebruiken na je controller.

dus : Welcome#index = Welcome controller & action is index.

Hier voorbeeld code :
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
    /**
     * Boot up the page.
     */

    private function _boot() {
        $router = new \AltoRouter();
        $router->setBasePath($this->_basePath);
        
        /**
         *
         * Include the router config file here.
         * Run a loop to get all routes.
         * Merge the hard routes and dynamic routes.
         */

        include SYS.CFG."Routes".EXT;
        /**
         * Load the dynamic urls in here.
         */

        $dynamicRoutes = $this->_getDynamicUrls();

        if($dynamicRoutes !== false) :
            $routes = array_merge($routes, $dynamicRoutes);
        endif;

        
        // pass thrue to route helper.
        require(SYS.HLP.'Routes'.EXT);
        \Routes::setRoutes($routes);
        /**
         * Map all the routes
         * @param array [$routes as $key => $route] create all the routes that are availeble.
         */

        
        foreach($routes as $key => $route) {
            $router->map(
                $route[0]
                ,
$route[1]
                ,
$route[2]
                ,
$key
            );
        }


        $match = $router->match();

        $this->_callToAction($match);
    }


    /**
     * Call the controller that is required
     * @param object $match Check if the route matches an controller.
     */

    private function _callToAction($match) {

        //var_dump($match);

        if ($match === false) {
            
            $this->_Error();
        }
else {
            
            list( $controller, $action ) = explode( '#', $match['target'] );
            
            if(file_exists(APP.CON.$controller.EXT)) {
                require APP.CON.$controller.EXT;
            }
elseif(file_exists(APP.CON.'Dashboard/'.$controller.EXT)) {
                require APP.CON.'Dashboard/'.$controller.EXT;
            }
else {
                $this->_Error();
                exit();    
            }

            $obj = new $controller();
            call_user_func_array(array($obj,$action), array($match['params']));
        }

    }

?>


Deze code gebruik ik in mijn bootstrap.
hopelijk kun je er wat mee !
 
Donald Boers

Donald Boers

15/05/2015 13:44:53
Quote Anchor link
Hoi Wouter hartelijk dank voor je reactie. Ik weet niet zeker of ik begrijp wat je bedoelt?

en dit is een voorbeeld van een van de routes:

'/rooms/[a:action]?/[i:id]?' => [
'controller' => 'Controller_Rooms',
'action' => 'index'
],


Bij voorbaat dank
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.