How to generate url of other application?

Hi, I use advanced application template, now I have a mail task that contains absolute frontend application url, but how to generate the frontend application url in console application?

I can store the frontend host in common/config/params-local.php, and concat it with the real path.
But is there exist a better solution?

Note: the task is trigger and run on console application only, so there is no way to pass the url from frontend to console.

Thanks.

Hi,

This topic is covered in the official guide for the advanced application: https://www.yiiframework.com/extension/yiisoft/yii2-app-advanced/doc/guide/2.0/en/topic-link-backend-frontend

What do you mean by “trigger”? Or, why isn’t it possible to pass some parameter?

What kind of URL do you want to write in the mail to be sent?

  1. The url of a mail confirmation page?
  2. The url of a file to be downloaded?
  3. The fixed url of some page?

If it is the 3rd one, I think your solution is quite reasonable. And in the first 2 cases you would have to pass some dynamic parameter anyway.

@machour I’m afraid it won’t help, because the issue is between a web app and a console app.

It was my understanding that it’s using the advanced application template, so the tutorial would apply for console too.

You can extract your urlManager configuration for frontend in a file, and include it in both frontend/config/main.php & console/config/main.php as suggested in the tutorial. Am I missing something? :thinking:

I’m not sure. Probably you are right in saying that we could use UrlManager in console app.
But IMO using it in console app is kind of overkill, because “URL” is something of a stranger in console app. I’d rather wanted to clarify the requirement.

1 Like

@machour @softark Thanks for your reply.

I need to generate frontend’s absolute url(for downloading) in console, such as schema://host:port/path?query..., the problem is that I don’t know how to store and retrieve the host info of frontend.

The guide is pretty good answer, I didn’t notice that there is a UrlManager's property baseUrl, it is better than storing the frontend’s host info in common/config/params.php.

Thanks a lot! :slight_smile: :+1:

1 Like