Arslaan Ejaz
Arslaan Ejaz

Reputation: 1001

How to get server url in model of ZF2

I want to get serverUrl in model. Which class i have to import and which function i have to call in my model to get server url. So in future i can easily change my urls in http to https in configuration only. Something like this.

use Zend\View\Helper\BasePath;

abstract class MysqliDB {

    protected function site_url(){

        $object = new BasePath();
        return $object->getView();
    }

}

Please Suggest me if i can do this or there any alternative for this.

Upvotes: 1

Views: 651

Answers (1)

Dinesh Sahoo
Dinesh Sahoo

Reputation: 80

You can use $_SERVER['HTTP_HOST'] for getting the host name/base url for your website.

Upvotes: 1

Related Questions