How to use pagination in laravel


Posted on 06 Mar 15 by Vickey

If we use pagination in core php then we need to write more code but if you are using laravel then it is very eassy to implement pagination functionality and no need to write more code so let go to implement pagination in laravel

Here i have a controller name BlogcontentController

class BlogcontentController extends BaseController {


I want to fetch all blogs with pagination so i cretaed a function manageblogs

class BlogcontentController extends BaseController {

    public function manageblogs()
        $this->layout->title = "Manage Blogs";

        $contentList = Blogcontent::orderby('created_at', 'desc')->paginate(15);

        $this->layout->content = View::make('content.mycontent')->with('contentList', $contentList);


in this function Blogcontent is the model name i have set 15 blogs per page

now in view part for show pagination links put the below code at the bottom of your page

<?php echo $contentList->links(); ?>

now enjoy with your pagination functionality

How to create yii 1.x web application on window


Posted on 06 Mar 15 by Vickey

If you are using yii 2 then no need to do this process but if you are using ver 1 then you can create yii application skeleton by doing these steps.when you will complete all the steps you can see a skeleton for yii application in your directory so lets go

Step 1. First download yii framework if you do not have

Step 2. Extract it in your web directory

Step 3. open cmd window and go in your webserver root folder. for example if you installed wamp in your C drive

cd C:\wamp\www\

Step 4. Now run command

php yii1.1.14/framework/yiic.php webapp myfirstapp

when process complete you can test it with url


How to change height and width dynamically of all images on a web page with js


Posted on 01 Mar 15 by Vickey

I was working on a elearning website and in this website div showing scrool if i upload a big image. I was showing images in a div. So i search the solution for this issue and i changed the height and width dynamicly with js code

The id of my div is pageDescription and i put this code

function managePagesContent()

    var getimage = document.getElementById("pageDescription").getElementsByTagName("img");
    for (var i=0; i 400)
            getimage[i].setAttribute('class', 'pageImage');

Here a added a new class 'pageImage' on images if image width is greater then 400


and now call function


and now i have solved the issue


How to add attributes on all anchors tags or div dynamicly in js


Posted on 28 Feb 15 by Vickey

I have a div which has an id 'parentdiv' and i want to add target blank on all anchors under this div

Here are my html

<div id="parentdiv">
<a href="">Link1</a>
<a href="">Link2</a>
<a href="">Link3</a>
<a href="">Link4</a>
<a href="">Link5</a>
<a href="">Link6</a>
<a href="">Link7</a>

First i create a function addattrib()

function addattrib(){

    var anchors = document.getElementById('parentdiv').getElementsByTagName('a');
    for (var i=0; i<anchors.length; i++)
        anchors[i].setAttribute('target', '_blank');
        anchors[i].setAttribute('class', 'linkcolor');

now call function


and now you can see your html like this

<a href="" target="_blank" class="linkcolor">Link1</a>
<a href="" target="_blank" class="linkcolor">Link2</a>
<a href="" target="_blank" class="linkcolor">Link3</a>
<a href="" target="_blank" class="linkcolor">Link4</a>
<a href="" target="_blank" class="linkcolor">Link5</a>
<a href="" target="_blank" class="linkcolor">Link6</a>
<a href="" target="_blank" class="linkcolor">Link7</a>

How to send message with twilio in cakephp


Posted on 27 Feb 15 by Vickey

How to send message with twilio in cakephp

Step 1. First download the and extract it in to app/Vender

Step 2. Import Twilio class in your controller

App::import('Vendor', 'twilio-php-master/Services/Twilio');
class MessagesController extends AppController 


Step 3 Now create a function for send sms

App::import('Vendor', 'twilio-php-master/Services/Twilio');
class MessagesController extends AppController 
    public function sendSms() {


Step 4 add code for send sms in your function

App::import('Vendor', 'twilio-php-master/Services/Twilio');
class MessagesController extends AppController 
    public function sendSms() {

        $MSG_HTML    = "Hi";
    $sid = "ACce5645176e37772fcff21384e2db86ee3b81"; /* Twilio id get it from Twilio account */
    $token = "5620c46560a5232b5a1a38b3bb657dc386370d7"; /* Twilio token get it from Twilio account */
    $client = new Services_Twilio($sid, $token);
    $sms = $client->account->sms_messages->create("YOUR TWILIO NUMBER", $cellnumber='PUT TO CELL NO HERE', $MSG_HTML, array());

Send email with smtp in cakephp


Posted on 21 Feb 15 by Vickey

You can send email by smtp in cakephp by these steps

Step 1. Go to app/config folder you will see file email.php.default rename it email.php

Step 2. Open file in edit mode and search

public $default = array(
    'transport' => 'Mail',
    'from' => 'you@localhost',
    //'charset' => 'utf-8',
    //'headerCharset' => 'utf-8',

when you find this code replace it with

public $default = array(
    'transport' => 'Smtp',
    'from' => array('your from email id' => 'Your website name'),
    'host' => 'ssl://',
    'port' => 25,
    'timeout' => 30,
    'username' => 'your gmail username',
    'password' => 'your password',
    'client' => null,
    'log' => false,
    'emailFormat' => 'html',
    'charset' => 'utf-8',
    'headerCharset' => 'utf-8',

and change you gmail account username and password

Step 3. Now create your email templete testemail.html under app/webroot/emails folder

and put you mail content in testemail.html file

Step 4. Open AppController.php and add

App::uses('CakeEmail', 'Network/Email');


public function send_mail($email_data = null)
         $email         = new CakeEmail('default');
        $email_to      = $email_data['to'];
        $email_msg     = $email_data['body'];
        $email_subject = $email_data['subject'];

        $mail_status = @$email->send($email_msg);
        if (!$mail_status) {
            return FALSE;
        return TRUE;

Step 5. Now in your action where you want to send email


$msg = file_get_contents(BASE_URL . "emails/testemail.html");
$data = array();
$data['to'] = 'email address';
$data['body'] = $msg;
$data['subject'] = 'Welcome';


Now you can send email in cakephp

How to force ssl in cakephp


Posted on 21 Feb 15 by Vickey

For force ssl in cakephp first create a file name as forcessl.php under app/controllers/components/

class forcesslComponent extends Object {

    var $components = array('RequestHandler');

    var $Controller = null;

    function initialize(&$Controller) {
        $this->Controller = $Controller;

    function forcetossl() {
        if(!$this->RequestHandler->isSSL()) {

    function unforcetossl() {
        if($this->RequestHandler->isSSL()) {

    function __url($default_port = 80)
        $port = env('SERVER_PORT') == $default_port ? '' : ':'.env('SERVER_PORT');
        return env('SERVER_NAME').$port.env('REQUEST_URI');

Now in your Controller add forcessl component

var $components = array('Auth', 'Forcessl' );

and in beforeFilter call forcessl action

App::import('Vendor', 'wepay/wepay');
class PaymentsController extends AppController 

    var $helpers = array('Html','Form');
    var $components = array('Auth', 'Forcessl' );

    public function beforeFilter() 

    public function index()


Please let me know if this help

How to generate basic code ( add, edit, view delete) in cakephp


Posted on 20 Feb 15 by Vickey

In this article i am using cake bake on ubuntu system with xampp server

In terminal window run command

sudo /opt/lampp/bin/php /opt/lampp/htdocs/cakephp-2.5.6/app/Console/cake.php bake


/opt/lampp/bin/php is the path of php and /opt/lampp/htdocs/cakephp-2.5.6
path of cakefolder in webroot folder

after run this command you can create model, controller and view code

How to get feeds in php


Posted on 15 Feb 15 by Vickey

Create a function name as getFeed

function getFeed($feed_url)

    $content = file_get_contents($feed_url);

    $x = new SimpleXmlElement($content);

    echo '<div class="blogList">';

    foreach($x->channel->item as $entry)

        if(strlen($recent["post_content"])> 100)
            $blogContent   =   rtrim(substr($entry->title,0,100)).'... ';
            $blogContent   =   rtrim($entry->title).'... ';

        echo "
        <div class='content'>
        " . $blogContent . "
        <a href='$entry->link' title='$entry->title' target='_blank' class='readMoreLink'>Read More</a>

    echo '</div>';

$feedurl is a the url of feed


How to get file format in php


Posted on 13 Feb 15 by Vickey

I was creating a elearning site and in this website i upload images, video and pdf files and in fronend i need to show these files. If the file is video then i show video player and if file is pdf or image then i use different method to show the file. so create a function to get file format. In this function

function getFileType($fileName)
    $resourceDetails   =   explode('.',$fileName);
    $resourceDetailsLength =   count($resourceDetails);
    if($resourceExtension=='mp4' || $resourceExtension=='3gp' || $resourceExtension=='wmv' || $resourceExtension=='avi' || $resourceExtension=='mov' || $resourceExtension=='flv')
    $resourceType  =   'video';
    elseif($resourceExtension=='mp3' || $resourceExtension=='wav')
    $resourceType  =   'audio';
    $resourceType  =   'pdf';
    elseif($resourceExtension=='jpg' || $resourceExtension=='png' || $resourceExtension=='gif' || $resourceExtension=='jpeg' || $resourceExtension=='JPG' )
    $resourceType  =   'image';
    $resourceType  =   'undefined';
    return $resourceType;

and call it where it needed


you can add more conditions for file format if needed