We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

2 questions - photos and redirection

I have two questions...

  1. I use this for photos upload:
$image = new Phalcon\Image\Adapter\GD('upload/objects/'.md5($objects->id).'0'.$ext);
$image->resize(500, 500);            
$objects->object_photo0 = ''.md5($objects->id).'0'.$ext; 

And now, I want to create 2 photos : the first one is in the above code, the normal photo, and now i want to create thumbnail like this:

$image = new Phalcon\Image\Adapter\GD('upload/objects/thumbs/'.md5($objects->id).'0'.$ext);
$image->resize(500, 500)->crop(500,500);            
$objects->thumb_photo0 = ''.md5($objects->id).'0'.$ext; 

How do I do this all together in one action?

  1. I have one action and i use it from two places. How can I determine from which action did the user come from, and redirect it to different page? Example: User comes from page A to controller, controller redirects it to page C. Also, user comes from B page to sme controller, controller redirects it to page D ?

edited Sep '14

Why not just copy the original image to thumbs/, and then you can crop it

You can use


to get the entire url where the user comes from, or you can track with a GET value.

then in your controller:

if ( /* comes from page A */ ) {
    return $this->dispatcher->forward([
        'action' => 'actionForPageA'

or if you just want to render a different view

if ( /* comes from page A */ ) {

  1. How do i copy it with phalcon?
  2. Can you please translate "/ comes from page A / to code for me please?

Tnx :)

  1. Don't know if you can. But use php function "copy"
  2. In controllers you can get the dispatcher, and get controller and action name to decide:
$dispatcher = $this->getDI()->get('dispatcher');


Excellent guys, thank you both :)


Marcus, when i try to echo $dispatcher->getControllerName(), nothing is echoed?