Giter Site home page Giter Site logo

lakinmohapatra / php-vars-to-js-transformer-for-codeigniter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from iarjunphp/php-vars-to-js-transformer-for-codeigniter

0.0 2.0 0.0 136 KB

PHP-Vars-To-Js-Transformer-For-CodeIgniter

Home Page: https://arjunphp.com

License: MIT License

PHP 98.38% HTML 1.62%

php-vars-to-js-transformer-for-codeigniter's Introduction

#Transform PHP Vars to JavaScript in CodeIgniter Framework

Often, you'll find yourself in situations, where you want to pass some server-side string/array/collection/whatever to your JavaScript. Traditionally, this can be a bit of a pain - especially as your app grows.

This codeIgniter library simplifies the process drastically

#Installation

Download the files add put PHPtoJS.php class in your library folderapplication\libraries\PHPtoJs.php.Now load the library locally or globally.

Locally

  $this->load->library('PHPtoJS');

Globally

Open you autoload.php file which located at application\config\autoload.php

$autoload['libraries'] = array('PHPtoJS');

After loading library, you may use in your controllers as shown below.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {


	public function index()
	{
            
            $this->load->library('PHPtoJS',['namespace' => 'arjun']);
            $this->phptojs->put([
                'foo' => 'bar',
                'age' => 29
            ]);
                       
	    $this->load->view('welcome_message');
	}
}

Final step in your layout page add this line

	 echo $this->phptojs->getJsVars(); 

php-vars-to-js-transformer-for-codeigniter's People

Contributors

iarjunphp avatar phpis avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.