Bin will be removed on June 1, 2014 in favor of http://gist.github.com. Please save all your pastes before then. So long, and thanks for all the fish!×
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
76
77
Regular requestAction call:
 
for ($i = 0; $i < 1000; $i++) {
    $this->requestAction(array('plugin' => 'galleries', 'controller' => 'galleries', 'action' => 'display', 'pass' => array('hello', 'world')));
}
 
Script Execution Time: 19.742 seconds
 
-------------------------------------------------------------------------------------------------------------------------------------------------
 
Alternative requestAction call using string url:
 
for ($i = 0; $i < 1000; $i++) {
    $this->rA('/galleries/galleries/display/hello/world');
}
 
Script Execution Time: 2.346 seconds
 
-------------------------------------------------------------------------------------------------------------------------------------------------
 
Alternative requestAction call using array url:
 
for ($i = 0; $i < 1000; $i++) {
    $this->rA(array('plugin' => 'galleries', 'controller' => 'galleries', 'action' => 'display', 'pass' => array('hello', 'world')));
}
 
Script Execution Time: 1.792 seconds
 
 
-------------------------------------------------------------------------------------------------------------------------------------------------
 
Alternative requestAction by biesbjerg:
 
function rA($url) {
    if (is_string($url)) {
        $url = Router::parse($url);
    }
    $defaults = array(
        'plugin' => null,
        'controller' => null,
        'action' => 'index',
        'pass' => array()
    );
 
    extract(array_merge($defaults, $url));
 
    $import = $controller;
    if (!empty($plugin)) {
        $import = $plugin . '.' . $controller;
    }
    if (!App::import('Controller', $import)) {
        return false;
    }
    $className = Inflector::camelize($controller . 'Controller');
    $Ctrl =& new $className();
    $Ctrl->plugin = $plugin;
    $Ctrl->params['requested'] = true;
    $Ctrl->constructClasses();
 
    switch (count($pass)) {
        case 0:
            return $Ctrl->{$action}();
        case 1:
            return $Ctrl->{$action}($pass[0]);
        case 2:
            return $Ctrl->{$action}($pass[0], $pass[1]);
        case 3:
            return $Ctrl->{$action}($pass[0], $pass[1], $pass[2]);
        case 4:
            return $Ctrl->{$action}($pass[0], $pass[1], $pass[2], $pass[3]);
        case 5:
            return $Ctrl->{$action}($pass[0], $pass[1], $pass[2], $pass[3], $pass[4]);
        default:
            return call_user_func_array(array(&$Ctrl, $action), $pass);
        break;
    }
}