Home> php教程> PHP开发> body text

Symfony2 implements the method of obtaining url in controller

高洛峰
Release: 2016-12-26 12:26:10
Original
1143 people have browsed it

The example in this article describes how Symfony2 implements the method of obtaining the url in the controller. Share it with everyone for your reference, the details are as follows:

// 假设当前URL地址是http://192.168.1.100/demo/web/app_dev.php/m/index $request = $this->getRequest(); // http or https 此处为http $request->getScheme(); // 192.168.1.100 $request->getHttpHost(); // http://192.168.1.100 $request->getSchemeAndHttpHost(); // /demo/web/ $request->getBasePath(); // /demo/index.php $request->getBaseUrl(); // eg: /demo/web/app_dev.php/user/login 不一定是/demo/web/app_dev.php/m/index 取决于routeName $this->generateUrl('routeName'); // routeName $routeName = $request->get('_route');
Copy after login

I hope this article will be helpful to everyone’s PHP program design based on the Symfony framework.

For more related articles on Symfony2’s method of obtaining the url in the controller, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!