PhalconAction controller pointer break down

I am new to Phalcon. I just got a general idea about this. Each controller has methods with several specific actions. I wrote a huge indexAction method, but now I want to break it down with several private methods so that I can reuse these functions. But when I try to create any method without an action suffix, it returns an error (Page not found).
How can I break it down into several methods?

+4
source share
3 answers
<?php

use Phalcon\Mvc\Controller;

class PostsController extends Controller
{
    public function indexAction()
    {
        $this->someMethod();
    }

    public function someMethod()
    {
        //do your things
    }
}
+2
source

"" , - "" . :

<?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.

0

What exactly do you want? The answer seems trivial to me.   

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()
    {

    }
}
0
source

All Articles