简体   繁体   中英

Has anyone used the tel: protocol in the Yii Framework?

The following code gets stripped down at runtime:

$PhoneHomeLink=CHtml::link($this->phone_home,'tel:'.$this->phone_home); 

Assuming the home phone number is 999-555-1212 the output is displaying:

<a>999-555-1212</a>

What happened to the:

<a href="tel:999-555-1212">999-555-1212</a>

Hi I thought this would be easy but I guess it's more work than I planned. Does anyone have any ideas?

OK for anyone interested, I tested the function in a few different places and it worked so I figured out it was implementation on my end.

I wanted to create tel: links inside CGridview with the following code:

'home'=>array('type'=>'html','name'=>'home_phone','value'=>'CHtml::link($data->phoneHome,"tel:".$data->phoneHome)','htmlOptions'=>array('width'=>'120')),

and after scratching my head and digging and digging I found out the alternate 'type' called raw which worked magic in this situation. I just needed one item in that line changed as shown here:

'home'=>array('type'=>'raw','name'=>'home_phone','value'=>'CHtml::link($data->phoneHome,"tel:".$data->phoneHome)','htmlOptions'=>array('width'=>'120')),

For Yii 2.x CHtml() is deprecated.

Use Html(). Here what I use in a DetailView::widget() for a phone number to be called.

        ['attribute' => 'CW_phone',
            'format' => 'raw',
            'value' => Html::a($model->CW_phone,"tel:".$model->CW_phone),
        ],

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM