Home > Backend Development > PHP Tutorial > How to use MC in Phalcon Micro application

How to use MC in Phalcon Micro application

WBOY
Release: 2016-07-06 13:52:10
Original
1087 people have browsed 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>
Copy after login
Copy after login

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

Reply content:

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>
Copy after login
Copy after login

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template