phalcon 控制器 indexAction 分解
phalcon controller indexAction break down
我是 Phalcon 框架的新手。我只是对它有了基本的了解。每个控制器都有包含多个特定操作的方法。我写了一个巨大的 indexAction 方法,但现在我想用多个私有方法将其分解,以便我可以重用这些功能。但是当我尝试创建任何没有操作后缀的方法时,它 returns error(Page Not Found).
如何将它分解为多个方法?
Controllers must have the suffix “Controller” while actions the suffix “Action”. A sample of a controller is as follows:
<?php
use Phalcon\Mvc\Controller;
class PostsController extends Controller
{
public function indexAction()
{
}
public function showAction($year, $postTitle)
{
}
}
调用其他方法,直接使用
<?php
use Phalcon\Mvc\Controller;
class PostsController extends Controller
{
public function indexAction()
{
echo $this->showAction();
}
private function showAction()
{
return "show";
}
}
Docs.
你到底想要什么?答案对我来说似乎微不足道。
class YourController extends Phalcon\Mvc\Controller
{
// this method can be called externally because it has the "Action" suffix
public function indexAction()
{
$this->customStuff('value');
$this->more();
}
// this method is only used inside this controller
private function customStuff($parameter)
{
}
private function more()
{
}
}
<?php
use Phalcon\Mvc\Controller;
class PostsController extends Controller
{
public function indexAction()
{
$this->someMethod();
}
public function someMethod()
{
//do your things
}
}
我是 Phalcon 框架的新手。我只是对它有了基本的了解。每个控制器都有包含多个特定操作的方法。我写了一个巨大的 indexAction 方法,但现在我想用多个私有方法将其分解,以便我可以重用这些功能。但是当我尝试创建任何没有操作后缀的方法时,它 returns error(Page Not Found).
如何将它分解为多个方法?
Controllers must have the suffix “Controller” while actions the suffix “Action”. A sample of a controller is as follows:
<?php
use Phalcon\Mvc\Controller;
class PostsController extends Controller
{
public function indexAction()
{
}
public function showAction($year, $postTitle)
{
}
}
调用其他方法,直接使用
<?php
use Phalcon\Mvc\Controller;
class PostsController extends Controller
{
public function indexAction()
{
echo $this->showAction();
}
private function showAction()
{
return "show";
}
}
Docs.
你到底想要什么?答案对我来说似乎微不足道。
class YourController extends Phalcon\Mvc\Controller
{
// this method can be called externally because it has the "Action" suffix
public function indexAction()
{
$this->customStuff('value');
$this->more();
}
// this method is only used inside this controller
private function customStuff($parameter)
{
}
private function more()
{
}
}
<?php
use Phalcon\Mvc\Controller;
class PostsController extends Controller
{
public function indexAction()
{
$this->someMethod();
}
public function someMethod()
{
//do your things
}
}