Home  >  Article  >  Web Front-end  >  createUrl和CHtml::link参数设置的区别_html/css_WEB-ITnose

createUrl和CHtml::link参数设置的区别_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-21 08:52:291613browse

createUrl将多个参数放进一个数组中,CHtml::link直接向后累计添加(不放进数组)1.createUrl和createAbsoluteUrlcreateUrl生成的是相对路径createAbsoluteUrl生成的是绝对路径在MVC中

$this->createUrl

在Yii中使用

Yii::app()->createUrl

<?php    $companyNew = (object)[        'id'=>'1',        'news_type'=>'boy',        'title' => '123'    ];    ?><a href="<?php echo $this->createUrl('controller/login',array('id'=>$companyNew->id,'news_type'=>$companyNew->news_type)) ?>" title="<?php echo $companyNew->title ?>">链接</a>

生成的html

<a href="/yii7/demos/test/index.php?r=controller/login&id=1&news_type=boy" title="123">链接</a>

2.CHtml::link

<?php echo CHtml::link('链接',array('controller/login','p'=>'cc','q'=>'dd'),array('target'=>'_blank'));?>

生成的html

<a target="_blank" href="/yii7/demos/test/index.php?r=controller/login&p=cc&q=dd">链接</a>

3.CHtml::linkButton

<?php echo CHtml::linkButton('LinkName', array('submit'=>array('controller/action','param'=>'value1'), 'confirm'=>"Are you sure?",));?>

生成的html

<a href="#" id="yt0">LinkName</a>/*<![CDATA[*/jQuery(function($) {  jQuery('body').on('click','#yt0',function(){if(confirm('Are you sure?')) {jQuery.yii.submitForm(this,'/yii7/demos/test/index.php?r=controller/action&param=value1',{});return false;} else return false;});});/*]]>*/
Statement:
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