首页 > Phalcon Micro应用中,如何使用MC

Phalcon Micro应用中,如何使用MC

官方文档中给出下面这样简单的例子

use Phalcon\Mvc\Micro;

$app = new Micro();

$app->get('/say/welcome/{name}', function ($name) {
    //do something
});

$app->handle();

所有处理代码都写fcunction里面,显然不可能,

get 访问 /say/getwelcome/{name} 时,想让它实例某个控制器,怎么做


感谢邀请,没用过这个框架,特地搜索了一下,然后只能说请这位亲仔细完整的阅读文档。请看 //对象内的方法部分。

<?php

//  函数
function say_hello($name) {
    echo "<h1>Hello! $name</h1>";
}

$app->get('/say/hello/{name}', "say_hello");

//  静态方法
$app->get('/say/hello/{name}', "SomeClass::someSayMethod");

//  对象内的方法
$myController = new MyController();
$app->get('/say/hello/{name}', array($myController, "someAction"));

// 匿名函数
$app->get('/say/hello/{name}', function ($name) {
    echo "<h1>Hello! $name</h1>";
});
【热门文章】
【热门文章】