Wednesday, July 28, 2010

php- Cakephp how to load helper in a component

Helpers can be loaded in to components and use as class objects

function index() {
App::import('Helper', 'Html'); // loadHelper('Html'); in CakePHP 1.1.x.x
$html = new HtmlHelper();
debug($html->link('Cake!', 'http://cakephp.org'));
}

Thursday, July 15, 2010

Php - creating table of values with fixed column from an array of values

Easily create tables

Use array_chunk($arrvalues, 2);

Array
(
[0] => Array
(
[0] => a
[1] => b
)

[1] => Array
(
[0] => c
[1] => d
)

[2] => Array
(
[0] => e
)

)


http://www.php.net/manual/en/function.array-chunk.php

Monday, June 14, 2010

Cakephp - Adding meta data to a website

meta(string $type, string $url = null, array $attributes = array(), boolean $inline = true)

This method is handy for linking to external resources like RSS/Atom feeds and favicons. Like css(), you can specify whether or not you'd like this tag to appear inline or in the head tag using the fourth parameter.


$html->meta(
'favicon.ico',
'/favicon.ico',
array('type' => 'icon')
);?> //Output (line breaks added)




$html->meta(
'Comments',
'/comments/index.rss',
array('type' => 'rss'));
?>

//Output (line breaks added)

Wednesday, June 9, 2010

Jquery : Attaching an event to multiple elements at one go

var a = $("#a");
var b = $("#b");
var combined = a.add(b);

Now u can use

combined.click(function () { /* */ });


this can be used in situation where u want to add same validation to two different forms

Thursday, May 13, 2010

Create a Simple Image Slide Show using jQuery









   Simple Slide Show with jQuery

   

   





   



Php- File upload limit changing using htaccess/php.ini

FASTCGI  / APACHE - Changing PHP File upload limit 
Php default maximum upload limit is 8 MB. You can change the default settings by changing the server settings using .htaccess file or custom php5.ini file in the case of godaddy hosting.   
First thing you have to find out is what your server API is?
print out php info of your hosted server.



See the  Server API value.
If  the Server API is apache You can do the following


1) Create a .htaccess file in the root folder of web server.
2) Put the following code in side the .htaccess file and save it.
php_value upload_max_filesize 20M
php_value post_max_size 20M
php_value max_execution_time 200
php_value max_input_time 200

 This will work in godaddy hosting.

If your Server API is CGI/FASTCGI do the follwing . 

create a php5.ini file and write in it

upload_max_filesize = 100M
post_max_size = 100M
output_buffering = on
max_execution_time = 1000
max_input_time = 1000
memory_limit = 64M

And upload it to your websites root folder.
Check the phpinfo and you can see the changes if it worked.Do not forget to put the file name php5.ini.

Thursday, May 6, 2010

Php-codeigniter creating thumbnails

I have created a library function


function image_resize($data)
{
$this->CI =& get_instance();
$error="";
$config['image_library'] = 'gd2';
$config['source_image'] = $data['source_image'];
$config['new_image']= $data['new_image'];
$config['create_thumb'] =$data['create_thumb'];
$config['thumb_marker'] = $data['thumb_marker'];

$config['maintain_ratio'] = TRUE;
$config['width'] = $data['width'];
$config['height'] = $data['height'];

$this->CI->load->library('image_lib');
$this->CI->image_lib->clear();
$this->CI->image_lib->initialize($config);
if ( ! $this->CI->image_lib->resize())
{
$error= $this->CI->image_lib->display_errors();
}

Wednesday, April 14, 2010

Javascript: To get base url of website in javascript

Use this script
put in in a common js file.

var domainbase ="http://" + window.location.toString().split("//")[1].split("/")[0] + "/";
var siteurl = domainbase + "site/";
var base_url = domainbase + "site/";

Tuesday, March 16, 2010

Php - How to remove index.php from codeigniter url

This is the best way to get ride of index.php from your website's url which is build using codeigniter framework.


RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]



copy and paste the above code in  .htaccess file in your website root.Ensure that no extra  whitspaces are included before or after the codes.

In config.php you can replace

$config['index_page'] = "index.php"; 
with this
$config['index_page'] = "";

Happy coding...