Yii Reference 1 – Create Url, Links and Redirections | HighND.com

Yii Reference 1 – Create Url, Links and RedirectionsPosted on September 19, 2011 This post will be a reference on how deal with urls, links and browser redirects in Yii Framework. It will guide you on how to use different built-in functions in Yii like createUrl, createAbsoluteUrl, CHtml::link, redirect.Create URL1 $url = Yii::app->createUrl’site/index’;Result: index.php?r=site/indexYou will obtain this format of URL if you’re not using the URL Manager to make your links more user-friendly.1 $url = Yii::app->createUrl’site/index’, array’id’=>100;Result: index.php?r=site/index&id=100 Create URL from Controller1 Yii::app->controller->createUrl”index”, array”id”=>100;Result: index.php?r=site/index&id=100You will obtain this result if your current controller is “SiteController”.If you are in a controller you can simply write1 $this->createUrl’index’,array’id’=>100; Create absolute URL:In order to create an absolute path url you need to use createAbsoluteUrl function:1 Yii::app->createAbsoluteUrl’site/index’,array’id’=>100;Result: http:⁄⁄yourdomain.tld⁄index.php?r=site⁄index&id=100 Create LinkYou can use the CHTML helper to quickly create an anchor in HTML:1 echo CHtml::link’text’, array’site/index’, ‘id’=>100;Result: text Redirect Browser1 $this->redirectarray’site/index’,’id’=>100;It will redirect the browser to index.php?r=site/index&id=100This entry was posted in Yii Framework and tagged php, web development, yii by admin. Bookmark the permalink.

via Yii Reference 1 – Create Url, Links and Redirections | HighND.com.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s