Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get the siteUrl from a Console Request #3055

Closed
andrelopez opened this issue Jul 3, 2018 · 4 comments
Closed

Unable to get the siteUrl from a Console Request #3055

andrelopez opened this issue Jul 3, 2018 · 4 comments

Comments

@andrelopez
Copy link
Contributor

andrelopez commented Jul 3, 2018

Description

I'm unable to the get the baseSite url within a console request. This stops working in v3.0.13

use craft\helpers\UrlHelper;
use Craft;
....
// Returns '/my-url'
$url = UrlHelper::siteUrl('my-url);

// Returns '/'
$baseUrl = Craft::getAlias("@web");

// Returns '/'
$baseUrl = UrlHelper::baseSiteUrl();

Steps to reproduce

  1. Call $baseUrl = UrlHelper::baseSiteUrl(); in a console request

Additional info

  • Craft version: 3.0.13.2
  • PHP version: 7.1.7
  • Database driver & version: Mysql
  • Plugins & versions: -
@brandonkelly
Copy link
Member

What is your primary site’s Base URL set to? Sounds like it might just be set to /.

@andrelopez
Copy link
Contributor Author

Hi @brandonkelly

I have added this to my init function of the plugin:

public function init()
    {
        $url = UrlHelper::siteUrl('my-url');
        Craft::dd($url);
        ....
    }

When I go to my dashboard in the browser I got:
'http://craft3.test/my-url'

The dashboard value is right but when I go to my console and try to run the craft command I got this:
no-site-url

My primary site has "@web/" in the baseUrl
sites

Best,

@andrelopez
Copy link
Contributor Author

If I set the my baseUrl to http://craft3.test it works.

So the @web alias does not work in console commands?

@brandonkelly
Copy link
Member

Correct, @web is just whatever the URL is that was requested by the browser. If it’s a console request, there is no requested URL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants