Migrating from Laravel to Phalcon

Auth

$this->user = $this->auth->getIdentity();

Requests

$this->request->get("type")

View

  • Specify a view

    $this->view->pick("item/close_window");

Database

$robots = $connection->fetchAll($sql);
$robot = $result->fetch();

Routes

Volt

Variable concatenation

{{ link_to("my/link/" ~ variable, "My Link") }}

Partials

{{ partial("layouts/header") }}
{{ partial('tags/tag-panel',['title': '@tags','tags': attag_items]) }}

If

{% if show_tags %}

{% endif %}

For

 {%- for tag in input_tags -%}

 {%- endfor -%}

Blocks

  • in layout template

    {% block javascript_footer %} {% endblock %}

  • in child template

Disable view and return json

In controller:

$this->view->disable();

echo json_encode([1, 2, 3]);

Routing

$router->addGet('/add',['controller' => 'item','action' => 'create']);
$router->addPost('/add',['controller' => 'item','action' => 'store']);
  • Get url of current page

    echo $this->router->getRewriteUri();

Responses

Json

 $this->view->disable();
 $this->response->setContentType('application/json', 'UTF-8');
 $this->response->setContent(json_encode($result));
 return $this->response;

or

header('Content-type:application/json;charset=utf-8');
echo json_encode($result);

Redirecting

return $this->response->redirect('/profile');

Auth

$identity = $this->auth->getIdentity();

Flash messages

$this->flash->notice('You don\'t have access to this module: private');

{{ flash.output() }}
<?php $this->flashSession->output() ?>

Debugging

 $debug = new \Phalcon\Debug();

$debug->listen();