We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon controller default

I wanted to learn how to create a controller and compile it in the Falcon? To have been there by default.



1.2k

Thank you, but not what I'm interested in the Phalcon Framework.



85.5k

its a bit too long to be explained properly ... zephir doesnt have much to do with Phalcon. They are 2 seperated projects.

Now the idea of zephir is to create your own namespace/classes.

So lets say you app is : MyApp. Create a new project using zephir named MyApp. Now inside following zephir structed, practices etc.. you create controllers / models and so on..

so we create our home/idnex controller

zephir:

namespace MyApp\Controllers;

class HomeController Extends Phalcon\Mvc\Controller ( orwherever its called ) {

    public function indexAction(){
        this->view->pick('common/index'); //or whatever you do in your idnex page
    }
}

now you compile your extension and you add to your php. Whereever this php version is running you will always be able to call

new \MyApp\Controllers\HomeController();

so with that cleared out, now what's left to be done in your phalcon project to tell that home/index controller is \MyApp\Controllers\HomeController and voage its working without even having this controller as php code in your project.

The tricky part is to make zephir working extending phalcon components, i remmeber I spend a day trying to figure it out. You can check check zephir issues there were some explanations going on there.

Now this is the basic idea, i guess you have to play a little bit with it in order to make it work. But its not complicated or anything like that, you just probably need a day or two. :-)

I think it should be wrote in some sticked thread how to extend phalcon, in zephir forum or in phalcon forum(or both).