dev-master
9999999-devThis is a set of useful helper function in one place packed to use with Yii2 framework. It will save you a lot of time.
MIT
The Requires
by Filip Ajdacic
helpers yii2 validate youtube truncate
This is a set of useful helper function in one place packed to use with Yii2 framework. It will save you a lot of time.
This is a set of useful helper function in one place packed to use with Yii2 framework. It will save you a lot of time., (*1)
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require --prefer-dist filipajdacic/yii2-helpers "*"
or add, (*4)
"filipajdacic/yii2-helpers": "*"
to the require section of your composer.json
file., (*5)
Once the extension is installed, simply use it in your code by putting this in your config:, (*6)
'components' => array( ... 'Helpers' => array( 'class' => 'filipajdacic\yii2helpers\Helper', ), ... );
Examples:, (*7)
validateEmail() - Validates email address, (*8)
$email = "example@mail.com"; $validate = Yii::$app->Helpers->validateEmail($email); if($validate) { echo 'Mail is Valid!'; } else { echo 'Email is not Valid!'; }
$email = "example@mail.com"; $encodedEmail = Yii::$app->Helpers->encode_email($email, 'Contact Me', 'class="emailencoder"'); echo "You can feel free to ".$encodedEmail;
$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque condimentum, augue vel finibus suscipit, erat lacus mollis urna, nec placerat nibh ex non felis. Morbi sit amet imperdiet dui. Lorem, Praesent pharetra sed orci in mollis. Pellentesque consectetur, turpis eu imperdiet feugiat, ipsum diam semper libero, eget mollis quam odio ullamcorper ligula. "; $highlighted_text = Yii::$app->Helpers->highlight_text($text, "Lorem", '#4285F4') echo'Your search results for word: Lorem are highlighted:
<Br>'; echo '<span>'.$highlighted_text.'</span>';
$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque condimentum, augue vel finibus suscipit, erat lacus mollis urna, nec placerat nibh ex non felis. Morbi sit amet imperdiet dui. Lorem, Praesent pharetra sed orci in mollis. Pellentesque consectetur, turpis eu imperdiet feugiat, ipsum diam semper libero, eget mollis quam odio ullamcorper ligula. "; $short_version = Yii::$app->Helpers->truncateText($text, 30, ' read more...'); echo ''; echo ''.$short_version.''; echo '';
```php, (*9)
$commentBody = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque condimentum, augue vel finibus suscipit, erat lacus mollis urna, nec placerat nibh ex non felis. Morbi sit amet imperdiet dui. or Click here to see my picture ' ";, (*10)
$comment_cleared = Yii::$app->Helpers->clearText($commentBody); echo ', (*11)
';, (*12)
6. **generateSlug()** - This function is useful if you would like to generate clean URL Slug. ```php $post_title = "Hey this Helpers will really help you!"; $url_slug = Yii::$app->Helpers->generateSlug($post_title); echo "<a href='/posts/".$url_slug."'>".$post_title."</a>";
$raw_url = "https://github.com/filipajdacic"; $tiny = Yii::$app->Helpers->getTinyurl($raw_url); echo $tiny;
$url = "http://github.com/filipajdacic"; $encoded_url = Yii::$app->Helpers->base64_encode($url); // output will be: aHR0cDovL2dpdGh1Yi5jb20vZmlsaXBhamRhY2lj
$url = "aHR0cDovL2dpdGh1Yi5jb20vZmlsaXBhamRhY2lj"; $decoded_url = Yii::$app->Helpers->base64_decode($url); // output will be: http://github.com/filipajdacic
$post_created_on = "2016-06-11 11:04:32"; $post_created_on_ago = Yii::$app->Helpers->timeAgo($post_created_on); // output will be: 6 months ago // But if you try like this: $post_created_on_ago = Yii::$app->Helpers->timeAgo($post_created_on,true); // output will be: 6 months 1 week, 23 hours, 51 minutes, 21 seconds ago
$youtube_link = "https://www.youtube.com/watch?v=L7oo21yfl7s"; $youtube_player = Yii::$app->Helpers->showYoutube($youtube_link); echo $youtube_player;
$vimeo_link = "https://vimeo.com/ondemand/indiegamethemovie/84887593"; $vimeo_player = Yii::$app->Helpers->showVimeo($vimeo_link); echo $vimeo_player;
$email = "ajdasoft@gmail.com"; $gravatar = Yii::$app->Helpers->showGravatar($email); echo "<div id="profile_picture">"; echo "<img src='".$gravatar."'> </img>"; echo "</div>";
$ip_address = Yii::$app->Helpers->showIP(); echo "Your IP address is:".$ip_address;
$link = "http://github.com/filipajdacic"; $qr_link = Yii::$app->Helpers->qr_code($link, 'URL'); $email = "ajdasoft@gmail.com"; $qr_email = Yii::$app->Helpers->qr_code($email, 'EMAIL'); $telephone = "+3816122233331"; $qr_phone = Yii::$app->Helpers->qr_code($telephone, 'TEL'); $text = "See ya! How are you?"; $qr_text = Yii::$app->Helpers->qr_code($text, 'TXT');
$lat_1 = '44.8014766'; $long_1 = '20.4516869'; $lat_2 = '44.7188265'; $long_2 = '21.1762609'; $distance = Yii::$app->Helpers->getDistanceBetweenCoordinates($lat_1, $long_1, $lat_2, $long_2); foreach ($distance as $unit => $value) { echo $unit.': '.number_format($value,4).'<br />'; }
$data = array("One", "Two", "Three"); Yii::$app->Helpers->pre_dump($data);
1.0, (*13)
MIT, (*14)
This is a set of useful helper function in one place packed to use with Yii2 framework. It will save you a lot of time.
MIT
helpers yii2 validate youtube truncate