Home >Backend Development >PHP Tutorial >How to use MC in Phalcon Micro application
The official documentation gives the following simple example
<code>use Phalcon\Mvc\Micro; $app = new Micro(); $app->get('/say/welcome/{name}', function ($name) { //do something }); $app->handle(); </code>
It is obviously impossible to write all processing codes in fcunction,
get
When accessing /say/getwelcome/{name}
, you want it to instantiate a controller. How to do it
The official documentation gives the following simple example
<code>use Phalcon\Mvc\Micro; $app = new Micro(); $app->get('/say/welcome/{name}', function ($name) { //do something }); $app->handle(); </code>
It is obviously impossible to write all processing codes in fcunction,
get
When accessing /say/getwelcome/{name}
, you want it to instantiate a controller. How to do it
Thanks for the invitation. I have never used this framework, so I searched for it, and then I can only say that I ask you to read the document carefully and completely. Please see the //对象内的方法
section.
<code><?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>"; });</code>