Rectangle 27 24

templating.helper.assets
# app/config/config.yml
framework:
    templating:
        assets_base_url: "http://www.mywebsite.com/"

Then just call the service from within your controller, command or wherever you are :

<?php

// src/Acme/Bundle/DemoBundle/Controller/DemoController.php

namespace Acme\Bundle\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DemoController extends Controller
{
    public function indexAction()
    {
        $myAssetUrl = $this
            ->get('templating.helper.assets')
            ->getUrl('bundles/acmedemo/js/main.js', $packageName = null)
        ;

        // $myAssetUrl is "http://www.mywebsite.com/bundles/acmedemo/js/main.js"

        return array();
    }
}

This is a great solution, as it is the most flexible one! You can put your assets anywhere you want (i.e. a CDN) in the future and only change the assets_base_url value in your config file.

Keep in mind that templating.helper.assets is only available when php templating engine is enabled.

symfony - How to get the full url for an asset in Controller? - Stack ...

symfony assetic
Rectangle 27 24

templating.helper.assets
# app/config/config.yml
framework:
    templating:
        assets_base_url: "http://www.mywebsite.com/"

Then just call the service from within your controller, command or wherever you are :

<?php

// src/Acme/Bundle/DemoBundle/Controller/DemoController.php

namespace Acme\Bundle\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class DemoController extends Controller
{
    public function indexAction()
    {
        $myAssetUrl = $this
            ->get('templating.helper.assets')
            ->getUrl('bundles/acmedemo/js/main.js', $packageName = null)
        ;

        // $myAssetUrl is "http://www.mywebsite.com/bundles/acmedemo/js/main.js"

        return array();
    }
}

This is a great solution, as it is the most flexible one! You can put your assets anywhere you want (i.e. a CDN) in the future and only change the assets_base_url value in your config file.

Keep in mind that templating.helper.assets is only available when php templating engine is enabled.

symfony - How to get the full url for an asset in Controller? - Stack ...

symfony assetic
Rectangle 27 7

The best solution would be IMHO to look at Twig's implementation of asset, which you can find in:

\Symfony\Bundle\TwigBundle\Extension\AssetsExtension

in the method:

public function getAssetUrl($path, $packageName = null, $absolute = false, $version = null)

which basically uses the templating.helper.assets service similar to @iamdto's answer:

$url = $this->container->get('templating.helper.assets')->getUrl($path, $packageName, $version);

Or directly use the AssetsExtension service or class respectively.

Yep, using the extension helper of the "asset" twig function is the most secure way. Thanks !!

symfony - How to get the full url for an asset in Controller? - Stack ...

symfony assetic
Rectangle 27 7

The best solution would be IMHO to look at Twig's implementation of asset, which you can find in:

\Symfony\Bundle\TwigBundle\Extension\AssetsExtension

in the method:

public function getAssetUrl($path, $packageName = null, $absolute = false, $version = null)

which basically uses the templating.helper.assets service similar to @iamdto's answer:

$url = $this->container->get('templating.helper.assets')->getUrl($path, $packageName, $version);

Or directly use the AssetsExtension service or class respectively.

Yep, using the extension helper of the "asset" twig function is the most secure way. Thanks !!

symfony - How to get the full url for an asset in Controller? - Stack ...

symfony assetic
Rectangle 27 0

You can obtain the URL of a file using the getUrl() method. So if imageFile is a ParseFile, you would get the URL in this manner:

imageFile.getUrl();

but how to use it it give me an error

android - Get link to image file at Parse.com - Stack Overflow

android image file parse.com
Rectangle 27 0

public class JsonParser {

    private static DefaultHttpClient httpClient = ConnectionManager.getClient();

    public static List<Club> getNearestClubs(double lat, double lon) {
        // YOUR URL GOES HERE
        String getUrl = Constants.BASE_URL + String.format("getClosestClubs?lat=%f&lon=%f", lat, lon);

        List<Club> ret = new ArrayList<Club>();

        HttpResponse response = null;
        HttpGet getMethod = new HttpGet(getUrl);
        try {
            response = httpClient.execute(getMethod);

            // CONVERT RESPONSE TO STRING
            String result = EntityUtils.toString(response.getEntity());

            // CONVERT RESPONSE STRING TO JSON ARRAY
            JSONArray ja = new JSONArray(result);

            // ITERATE THROUGH AND RETRIEVE CLUB FIELDS
            int n = ja.length();
            for (int i = 0; i < n; i++) {
                // GET INDIVIDUAL JSON OBJECT FROM JSON ARRAY
                JSONObject jo = ja.getJSONObject(i);

                // RETRIEVE EACH JSON OBJECT'S FIELDS
                long id = jo.getLong("id");
                String name = jo.getString("name");
                String address = jo.getString("address");
                String country = jo.getString("country");
                String zip = jo.getString("zip");
                double clat = jo.getDouble("lat");
                double clon = jo.getDouble("lon");
                String url = jo.getString("url");
                String number = jo.getString("number");

                // CONVERT DATA FIELDS TO CLUB OBJECT
                Club c = new Club(id, name, address, country, zip, clat, clon, url, number);
                ret.add(c);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        // RETURN LIST OF CLUBS
        return ret;
    }

}
Again, its relatively straight forward, but the methods Ill make special note of are:

JSONArray ja = new JSONArray(result);
JSONObject jo = ja.getJSONObject(i);
long id = jo.getLong("id");
String name = jo.getString("name");
double clat = jo.getDouble("lat");

java - get JSON object from a HTTP response - Stack Overflow

java android json
Rectangle 27 0

"public String getUrl () gets the URL for the current page. This is not always the same as the URL passed to WebViewClient.onPageStarted because although the load for that URL has begun, the current page may not have changed." (c) Android Developers

So, if your page doesn't load yet then getUrl returns null to you. Try to call it, for exampe, in onPageFinished in your custom WebViewClient.

i have already use it before then it is work between 4.1 - 4.4. but when i use the 4.0 device which just not working.

@user2357288 I tested it on HTC Sensation (4.0). All worked fine.

i still can not fix the issue. but i used another method to handle this. maybe that will be simple and flexible. anywhere, thanks for your advise. =]

Android webview get url return null - Stack Overflow

android url webview
Rectangle 27 0

You need Mage::getUrl and instead of just getting the base domain it can be used to get the finished URL in one go.

Mage::getUrl('path/to/notification', array('_store' => 'admin'));

Would not take the default shop because it can also be on a subdomain and the installation does not @clockworkgeek

php - How to get the base url where magento is installed? - Stack Over...

php magento base-url
Rectangle 27 0

String theUrl;
WebView webView = new WebView(this);
setContentView(webView);

webview.setWebViewClient(new WebViewClient() {

    public void onPageFinished(WebView view, String url) {
        theUrl = url;
    }

});

webView.loadUrl(myURL);

if i use this: String a= url.toString(); a = webView.getUrl();

geturl - Android- how to get the url of the webView? - Stack Overflow

webview geturl