Skip to content

Instantly share code, notes, and snippets.

@Andrew8xx8
Created April 4, 2011 08:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andrew8xx8/901297 to your computer and use it in GitHub Desktop.
Save Andrew8xx8/901297 to your computer and use it in GitHub Desktop.
Примеры использования различных функций и виджетовв yii
<?php
/**
* Генерация ссылок
*/
// Создать урл по псевдониму пути
// В зависимости от настроек урлменеджера вернёт полный http путь к скрипту
// например http://webapp.local/index.php?r=site/index
Yii::app()->createUrl('site/index');
// Задача. Создать и вывести ссылку
// Результат <a href='http://examples.sites'>тест ссылки<a/>
echo CHtml::link('тест ссылки', 'http://examples.sites');
// Cоздать и вывести ссылку по экшну
// Результат <a href='http://webapp.local/index.php?r=site/index'>тест ссылки<a/>
echo CHtml::link('тест ссылки', Yii::app()->createUrl('site/index'));
// задать ссылке свои html атрибуты
// Результат <a href='http://examples.sites' class='test' id='test'>тест ссылки<a/>
echo CHtml::link('тест ссылки', 'http://examples.sites', array(
'class' => 'test',
'id' => 'test'
));
/**
* AJAX
*/
// возвращает true если это аякс запрос
Yii::app()->request->isAjaxRequest;
// Многоязычность
// первый параметр - имя файл с переводом без расширения и пути
// второй - фраза на исходном языке приложения
Yii::t('', '');
// создать и вывести ссылку ('модуль с переводом', 'текст ссылки', 'путь к экшну')
echo CHtml::link(Yii::t('', ''), Yii::app()->createUrl(''));
/**
* снипеты
*/
Yii::app()->createUrl('');
echo CHtml::link('', '');
echo CHtml::link('', '', array(
'' => ''
));
echo CHtml::link(Yii::t('', ''), Yii::app()->createUrl(''));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment