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

attribute Src to controller not found

Hi, I have an old system and I'm moving to Phalcon. Now I have a problem with an iframe when setting the SRC attribute:

This works (old system): $ ('# Printframe'). Attr ('src', '/ common / print.php');

That's not how Phalcon works Params = type + "/" + temp + "/" + wait + "/" + saleNum + "/"; Var url = "<? Php echo $ this-> url-> get (" common / index / ");?>" FullUrl = url + params $ ('# Printframe'). Attr ('src', fullUrl);

I understand that before it worked because I sent a file print.php in the path, but now with phalcon I am sending the path of the driver and does not contain .php

How can I solve it?

edited May '17

If you've configured your webserver (nginx/apache/whatever) correctly, existing files should be served properly, so if you place a print.php in you web root, navigating to domain.com/print.php would still run that piece of code.

If you want to fully migrate to Phalcon, create a controller for it, for eg:

class CommonController extends PhController
{
    public function printAction() {
        $this->view->disable();
        echo 'raw stuff...';
    }
}

and then you can use this in your JS code:

$ ('# Printframe'). Attr ('src', '/common/print');

You could also set up a proper name for your route which replicates your old URL, so you don't have to change the JS part:

$router->add('/common/print.php', [
    'controller' => 'common',
    'action' => 'print'
]);
edited May '17

Ok, and where do I put this code?

$ Router-> add ('/ common / print.php', [ 'Controller' => 'common', 'Action' => 'print' ]);

Remember that extra parameters are also sent ...



77.7k
Accepted
answer
edited May '17

That line should be somewhere in your service definitions. I don't know about your project layout,, but for eg. the vokuro sample app puts it here: https://github.com/phalcon/vokuro/blob/bd0f5bba9f4af00e94e9bc3934ac8648d01fe978/app/config/routes.php

Extra parameters (/common/print.php/{param1}/{param2}) will be forwarded to your printAction($param1, $param2) automatically if you define your route name like this: /common/print.php/:params.

If you mean query parameters (/common/print.php?name=foo), then those can be accessed by $this->request->getQuery("name") in your action.

very good! thanks!