Welcome Guest, Not a member yet? Register   Sign In
MY MY_url_helper.php File!
#1

[eluser]SpYk3[/eluser]
This has been ubberly useful to me for years, so I figured I'd share. Keep in mind this Extension is based on setting folders like `js` to the main directory.

It provides methods like:

js_url('somefile.js'); - get path of JavaScript Directory. Pass in file name or dir/file to get a complete file path.
css_url('somefile.css'); - get path of Style Sheet Directory and files
images_url('someimage.png') - Same as previously mentioned

Also included are some useful methods, not really url related, but i just always squeeze in this file. Not any real reason for a whole nother file just for 1 simple method.

preDump(params); - Just like var_dump, except it add `PRE` tags around what it dumps to view. gives a much nicer and cleaner view.

Lastly included are a couple simple functions for getting URL Parameters and Dumping them to view.

urlParams(); - Get's array of url parameters, like $this->input->get(), except it checks both GET and POST
urlParamsDump(); - Uses preDump function to show urlParams


Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
* CSS URL
*
* Create a local URL based on your CSS Path.
* Segments can be passed in as a string or an array, same as site_url
* or a URL to a file can be passed in, e.g. to an image file.
*
* @access public
* @param string
* @return string
*/
if (!function_exists('css_url')) { function css_url($uri = '') { return base_url('css/'.$uri); } }

/**
* JS URL
*
* Create a local URL based on your JavaScript Directory Path.
* Segments can be passed in as a string or an array, same as site_url
* or a URL to a file can be passed in, e.g. to an image file.
*
* @access public
* @param string
* @return string
*/
if (!function_exists('js_url')) { function js_url($uri = '') { return base_url('js/'.$uri); } }

/**
* Images URL
*
* Create a local URL based on your Images Directory Path.
* Segments can be passed in as a string or an array, same as site_url
* or a URL to a file can be passed in, e.g. to an image file.
*
* @access public
* @param string
* @return string
*/
if (!function_exists('images_url')) { function images_url($uri = '') { return base_url('images/'.$uri); } }

/**
* Pre Tagged var_dump
*
* Executes var_dump with <pre> tags as a wrapper.
*
* @access public
* @param anything, multiples accepted
* @echo <pre>var_dump</pre>
* @return NULL
*/
if (!function_exists('preDump')) { function preDump() { echo("<pre>"); foreach (func_get_args() as $arg) var_dump($arg); echo("</pre>"); return; } }

/**
* Return $_GET || $_POST
*
* Return get or post if available, else return FALSE
*
* @access public
* @return Array
*/
if (!function_exists('urlParams')) { function urlParams() { $CI = get_instance(); return $CI->input->get() ? $CI->input->get() : $CI->input->post(); } }

/**
* preDump URL Parameters found, else will dump FALSE
*
* Echo a pre tagged statement of URL parameters
*
* @access public
* @echo <pre>var_dump($_GET||$_POST)</pre>
* @return NULL
*/
if (!function_exists('urlParamsDump')) { function urlParamsDump() { preDump(urlParams()); return; } }
#2

[eluser]jairoh_[/eluser]
We appreciate your contribution sir.
#3

[eluser]quickshiftin[/eluser]
Very nice!




Theme © iAndrew 2016 - Forum software by © MyBB