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

2 questions - photos and redirection

I have two questions...

  1. I use this for photos upload:
$file->moveTo('upload/objects/'.md5($objects->id).'0'.$ext);
$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:

$file->moveTo('upload/objects/thumbs/'.md5($objects->id).'0'.$ext);
$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 ?


1.7k
edited Sep '14

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


You can use

$_SERVER['HTTP_REFERER']

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 */ ) {
    $this->view->pick('viewForPageA');
}


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

Tnx :)



13.7k
Accepted
answer
  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');
$dispatcher->getControllerName()
$dispatcher->getActionName()


17.0k

Excellent guys, thank you both :)



17.0k

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