Scroll page down when page load

Jquery

Posted on 09 Apr 15 by Vickey
  455

Here are two method for scrool page down or bottom

$(document).ready(function(){ window.scroll(0,2000); });

scroll page by giving height

$(document).ready(function(){ $(window).scrollTop(jQuery(document).height());});

 

scroll page by getting window height dynamicaly

Auto scroll page down based on window height

Jquery

Posted on 09 Apr 15 by Vickey
  516

In the below code first we get the window height and then accordingly scroll page

$(document).ready(function(){ 

if(jQuery(window).width() < 300) window.scroll(0,1000); else if(jQuery(window).width() < 600) window.scroll(0,2000);

});

How to join multiple table with Query Builder in yii

php

Posted on 07 Apr 15 by Vickey
  760
public function actionClasslist()
{
    $gym=$this->data['user_id'];
    $data = Yii::app()->db->createCommand()
    ->select('c.title, a.name, cs.attendance')
    ->from('class_signed cs')
    ->join('class c', 'c.id = cs.class_id')
    ->join('student a', 'a.id = cs.student_id')->where(array('id'=>$teacher))->order('cs.date ASC')->group('cs.student_id')->queryAll();
    $this->render('view',array('model'=>$data));

}

 

How to implement design or theme in laravel

Laravel

Posted on 24 Mar 15 by Vickey
  576

Laravel use blade template engine. so in all view files we use blade extension for example test.blade.php In this post i am implementing design or theme on my application. Here are some steps to implement design on a web application. here I am working on laravel5 and creating home page

  • so first go to laravel5/app/Http directory and open routes.php and put this code

    Route::get('home', 'HomeController@index');

  • Now go in laravel5/app/Http/Controllers and create a controller HomeController.php if not exist

    namespace App\Http\Controllers; class HomeController extends Controller {

    public function __construct()
    {
        //$this->middleware('auth');
    }
    
    
    public function index()
    {
        return view('home');
    }
    

    }

  • go in laravel5/resources/views and create a file app.blade.php and add html for your header, footer and head for example

    Your title

    @yield('content')

    www.000webhost.com

@yield('content') used for fetch content from view

  • put all css js, and images in public folder at root of your application

  • in next step create a file home.blade.php for action 'index' as you can see in index action i used 'return view('home');'

put this code home.blade.php

@extends('app')
@section('content')

    <div>Your content</div>

@endsection

now you app layout will be used in this view

when you will browse it your site url/home

you can see this page with layout. and by Ctrl U you can see all element like footer header and your content. and you can manage its UI by adding css or html in app.blade.php file

hope this will help you

Remove defualt javascript files from head in yii

Yii

Posted on 17 Mar 15 by Vickey
  761

In yii there are many javascript and css files load by defualt and these can break our custom js or css. if you will check your header code then these will not appear but on load time these comes dynamiclly. we can remove these files by writing some code in our Controller.php under /app/Components/. go to Controller.php file and search init() function if it does not exist create new

public function init(){

}

and now add

public function init(){

    Yii::app()->clientScript->scriptMap=array('jquery.yiiactiveform.js'=>false,'jquery.min.js'=>false);
}

in this code which file you do not want to load make it false like in this example i made jquery.yiiactiveform.js'=>false

How to make url seo friendly in cakephp

Cakephp

Posted on 17 Mar 15 by Vickey
  1622

In cakephp we can manage our url in routes.php file under /app/Config directory. If you want to create seo friendly url you can define your url in routes.php. In this example i am creating a user profile url in this url we will not show controller and action name we only show username so our will look like example.com/pk

I have controller UsersController and action profile in this case i use url example.com/pk then we can get pk as username in our action

class UsersController extends AppController {

    public function profile($username='') 
    {

        echo $username; die;

    }

}

the out put of this action will be pk

for doing this add this code in your routes.php file

Router::connect(
'/:user_name', array(
    'controller' => 'users', // default controller 
    'action' => 'profile' // default action 
), array(
    'pass' => array('user_name'), username to your action
    'username' => '[a-zA-Z0-9@_\s]+' // regular expression match parameter 
    )
    );

where user_name will be the last parameter in url users is the controller and profile is the action

How to redirect from 404 page to home page automatically after a delay

Js

Posted on 16 Mar 15 by Vickey
  449

If user try to open a non existing url then website show 404 page. It means page not found. if you want to rediret automatically on other page if he is on 404 page then you can use javascript function

setTimeout(function() { window.location='/'; }, 5000);

In this code setTimeout is a javascript function and 5000 is the time ( 5 seconds ). after 5 seconds the page will redirect on home page. you can increase or decrease the time and change the url for redirection

Create error 404 page if page not found or url not exist in laravel

Laravel

Posted on 13 Mar 15 by Vickey
  2553

In laravel if you put wrong url then it will give defualt error. This error message always same in all types of error. But if you want to redirect on custom 404 page in case of if user put wrong url or url does not exist then you can create custom 404 page. by these steps

Go to /app/start/global.php and put the below code

App::missing(function($exception)
{
   return Redirect::action('ErrorController@error');
});

if you dont want use controller then

App::missing(function($exception)
{
   return Response::view('error.error', array(), 404);
});

Now open /app/routes.php and add

Route::get('/error404', 'ErrorController@error');

After save these files go in app/controllers and create a new controller and add

class ErrorController extends BaseController {

public $layout = 'layouts.admin';


public function error()
{
    $this->layout->title = "Laravel";
    $this->layout->content = View::make('error.error');
}



}

Now create View for this controller and action

go in /app/views and craate a folder name as error and create a file name as error.blade.php under error folder

Now in last open file app/config/app.php and search

debug' => false, in this file and replace it with <code>'debug' => true,

Now you can test this by puting wrong url

How to change defualt Auth fields in cakephp

Cakephp

Posted on 10 Mar 15 by Vickey
  537

The defualt auth fields in cakephp are username and password but if you want to use email or phonenumber at the place of username then you can modify your auth component in your controller. You can change model name also. cakephp Auth component defualt model is User. But by this method you can change this You nede to use this code in your controller

public $components = array('Session', 'Cookie',
    'Auth' => array(
        'authenticate' => array('Form' => array( 'userModel' => 'User',
                    'fields' => array(
                                        'username' => 'cellnumber',
                                        'password' => 'password'
                                        ),
                                                                                                //'scope' => array('is_active' => '1')
                                )
            ),
    ),
);

here i am using cellnumber as username

How to fetch record which inserted within one week in laravel

Laravel

Posted on 07 Mar 15 by Vickey
  2106

In my application i need to show last 7 days data in graph form and i am using laravel. For fetch 7 days old data first i need to know the date before 7 days. for get date before 7 days i used

$7days_ago_date = date('Y-m-d', strtotime('-8 days', strtotime(date('Y-m-d'))));

and now i have date before 7 days

i put this date in find query of laravel

$Tracker = Tracker::orderby('created_at', 'desc')->whereBetween( DB::raw('date(created_at)'), [$7days_ago_date, date('Y-m-d')] )->get();

and now i have all rows which inserted in last week to till