0

I have an Entity called Shop in which it has a property called domainURL. In my twig I did the following:

<a href="{{ shop.getSubdomain() }}">

However this always appends my root directory to the subdomain resulting in:

www.mydomain.com/somesubdomain.test.com

How can I just get the URL?

Here's the code for getSubdomain():

  /**
     * @ORM\Column(name="subdomain", type="string", length=50, nullable=true)
     */
    protected $subdomain;


 /**
     * Get subdomain
     *
     * @return string 
     */
    public function getSubdomain()
    {
        return $this->subdomain;
    }
4

1 回答 1

2

I'm pretty sure the browser only displays the url prepended with the current domain because the link's href is a relative url (missing the scheme as Touki pointed out) instead of an absolute one.

I would use {{ app.request.scheme ~ '://' ~ shop.subdomain }}

info: twig will automatically call the getter, no need to use shop.getSubdomain() !

于 2013-09-20T09:52:35.180 回答