Ionut Flavius Pogacian
Ionut Flavius Pogacian

Reputation: 4811

yii chtml link not working properly

I have a absolute url: http://www.linkbook.co/

When I use a grid view and within a column I use:

        array(
            'type' => 'raw',
            'header' => 'Url',
            'value' => 'CHtml::link($data->location,$data->location,array("target"=>"_blank"))',
        ),

, when a user clicks on the link, a new tab opens within the browser;

Now, if the link is not absolute, yii chtml link concats the app current url with given url, so I get:

http://localhost/frontend/user/url/index/id/www.william.ro

What can I do in order to get a new tab opened with the not absolute url?

Upvotes: 0

Views: 847

Answers (2)

DaSourcerer
DaSourcerer

Reputation: 6606

I think a better way were this:

array(
    'header'=>'Url',
    'name'=>'location',
    'type'=>'url',
),

This will invoke CFormatter.formatUrl(), which will automatically prepend http:// if no scheme is found.

Upvotes: 1

Developerium
Developerium

Reputation: 7265

follow this link :

Normalizes the input parameter to be a valid URL.

If the input parameter is an empty string, the currently requested URL will be returned.

If the input parameter is a non-empty string, it is treated as a valid URL and will be returned without any change.

If the input parameter is an array, it is treated as a controller route and a list of GET parameters, and the CController::createUrl method will be invoked to create a URL. In this case, the first array element refers to the controller route, and the rest key-value pairs refer to the additional GET parameters for the URL. For example, array('post/list', 'page'=>3) may be used to generate the URL /index.php?r=post/list&page=3.

Upvotes: 1

Related Questions