Archive

Archive for the ‘php freelancing india mumbai’ Category

CakePHP – Import a Controller using App::import()

October 8, 2011 Leave a comment

Hi All,

Have you ever use controller inside another controller(two controllers) in CakePHP ? If you are looking for the same thing, you are at the right place. I was working with CakePHP and i need to use a member info method of member controller in order controller(two controller in CakePHP). Instead of writing a code again in order controller, i searched for using controller inside controller. This can be easily done using App::import method of CakePHP.

App::import('Controller', 'Members');
class OrdersController extends AppController {
    var $Members;
    function beforeFilter() {
        $this->Members =& new MembersController; // Loads the class
        $this->Members->constructClasses(); // Loads the model associations, components, etc. of the Members controller
    }
    function index() {
        $this->Members->memberinfo();
    }
}

 


										

CodeIgniter – Extending the native ‘Model’ and make it your own.

October 3, 2011 Leave a comment

Hi All,

Today I took advantage of CodeIgniter’s ability to extend the native libraries, and I was well satisfied that it just works.

Codeigniter Development India

Let me elaborate, I’m in the process of creating models for my CI project, and realized that certain functions within the models were getting repetitive. Using CI’s ability to create my own custom libraries, I was able to create my own custom ‘Model’ which extends from the core ‘Model’ object. How this simple architecture has cleaned up my code is simply remarkable.

So read on…

CI has some pretty great documentation to get a beginner CI coder up to speed. In the case of using models, the docs says you need to extend from the CI’s core ‘Model’ object.Typically the code will be something like this:

—–

class Model_name extends Model {
	function Model_name() {
		parent::Model();
	}
}
-----
Given that Models are generally library functions to your database, certain 
functions like create,  read, update and delete would be common across all models.
 In which case the code will probably  start to look like this:
------
class Model_name extends Model {

	function Model_name() {
		parent::Model();
	}

	function create() {
		//do insert data into database
	}

	function read() {
		//do get data into database
	}

	function update() {
		//do update data into database
	}

	function delete() {
		//do delete data from database
	}
}
------

Imagine having to repeatedly write (opps, cut-and-paste) that same 4 (or more) functions to every model you create. A better way would be to consolidate those functions into a parent Model, and your models inherit from the parent their ability to create, read, update and delete.

One way you can do this is to just edit and insert these functions into CI’s native Model code which you can find in system/libraries/Model.php. But when it comes to upgrading the core when a new version is released, you may end up overriding those changes you need.

A much better way is to create your own model object called MY_Model and inherit it’s capabilities from the core Model. (Do note that ‘MY_’ is the default prefix set in CI for extending native libraries, but the prefix can be changed. Read the docs.)

This is how you do it, you create a new php file, MY_Model.php in the applications/libraries/folder. The code for MY_Model would look something like this:

——–

class MY_Model extends Model {

	function MY_Model() {
		parent::Model();
	}
	function create() {
		//do insert data into database
	}

	function read() {
		//do get data into database
	}

	function update() {
		//do update data into database
	}

	function delete() {
		//do delete data from database
	}
}
--------
Now, within your models at applications/models folder, you would do something like this:
class Model_name extends MY_Model {
	function Model_name() {
		parent::MY_Model();
	}
}

And within your controllers at applications/controllers folder, you would be able to access 
the common functions of create, read, update and delete as you would normally.
------
class Blogs extends Controller {
	function view() {
		$this->Model_name->read();
	}
}
------

And that’s it. I know it’s very skeletal, but it should give you some ideas on how to proceed to extend the native core libraries CI comes with. Of course, this method doesn’t just apply to ‘Model’, you can extend any of the CI core objects. The CI docs have a good intro to extending the native library.

Also, I would like to give a nod to Emram at PHPFour for his Extended Model for CodeIgniter which basically incorporates CakePHP-like model capabilities into the CI Model.

Do bear in mind his method is to replace the system/libraries/Model.php file which is not recommended, for reasons I mentioned before. However, you should be able to incorporate his work by extending from the native library.

Contact:

bhavinran07[@]gmail.com

Categories: CakePHP, CakePHP Developer India, freelance developer, Freelance PHP Developer, Freelance PHP Programmer, Freelance Programmer India, Hire Dedicated Programmer, Hire Dedicated Programmer India, Hire PHP Developer India, Hire PHP Professional, Hire PHP Professional India, Hire PHP Programmer India, iphone developer, JavaScript, joomla, joomla customization india, Joomla Developer, joomla developer india, joomla freelancer india, jquery, mysql, open sources developer india, oscommerce Customization, oscommerce developer, php, PHP Development, PHP Freelance, PHP Freelancer, PHP Freelancer India, php freelancing india, php freelancing india mumbai, Php programming, web designer, web designer india, Web Developement Company USA, web developer, web developer ahemdabad india, web developer india, Web development India, Wordpress Developer India, wordpress freelance developer, wordpress freelance programmer, wordpress freelancer, Wordpress Freelancer India, Wordpress Programmer, Wordpress Shopping Cart, Wordpress theme customization, wordpress theme integration, x cart development india Tags: , , , , , , , , , , , , , , , , , , , , , ,

PHP Web Development, Custom PHP Development of India based OPS – Instant, Interactive, Inexpensive (freelance php developer programmer wordpress joomla drupal and many open sources, cakephp and many frameworks)

October 2, 2011 3 comments

PHP Web Development, Custom PHP Development of India based OPS – Instant, Interactive, Inexpensive (freelance php developer programmer wordpress joomla drupal and many open sources, cakephp and many frameworks).

😀

Need to develop website in PHP? Want to develop custom applications in PHP? Looking for PHP development services at affordable costs? Then your search ends here.

Outsourcing Programming Services (OPS) – A leading PHP development company from India offers PHP web developmentservices at cost effective rates. Develop your custom high end applications through PHP development services. Increase business efficiency level and reduce business overheads by outsourcing custom PHP development requirements to us.

Request a Quote to know your PHP development costs for FREE, visit: https://bhavinrana.wordpress.com/

PHP Development Services by OPS:

• Custom PHP Development: Customized development with desired features and dynamic functionality
• PHP Application Development: Develop business web applications with elegant application user interface design
• PHP eCommerce Website Development: eCommerce shopping cart development services using Magento, CS Cart, VirtueMart, X-Cart, Zen Cart, etc.
• PHP MySQL Development: Develop dynamic and database driven website applications with PHP and MySQL
• Open Source PHP Implementation and Customization: Helps to develop and implement PHP Open Source Applications for businesses on open source and PHP platform i.e. LAMP, WAMP
PHP Web Development with MVC architecture: Develop web applications using CakePHP, Zend framework and CodeIgniter.

Based in India, leading PHP Development Company provides total PHP development solutions for various businesses & industries. It has a team of best Indian PHP developers who has developed and delivered thousands of custom PHP applications at affordable rates.

Drop a brief of PHP development requirements and get assisted by PHP Development experts in almost no time.

Contact:

bhavinrana07[@]gmail.com

Categories: ajax, Androide developer, CakePHP, CakePHP Developer India, drupal freelancer india, Freelance PHP Developer, Freelance Programmer India, freelance web, freelance web designer, Freelance web developer, get a freelancer, Graphic Designer, Hire Dedicated Programmer, Hire Dedicated Programmer India, Hire PHP Developer India, Hire PHP Professional, Hire PHP Professional India, Hire PHP Programmer India, iOS, iphone 4, iphone application developer, iphone developer, iphone website designer, JavaScript, joomla customization india, Joomla Developer, joomla developer india, joomla freelancer india, jquery, mysql, open sources developer india, oscommerce Customization, oscommerce developer, php, PHP Developer, PHP Developer India, PHP Development, PHP Freelance, PHP Freelancer, PHP Freelancer India, php freelancing india, php freelancing india mumbai, PHP programmer, Php programming, web design india, web designer, web designer india, Web Developement Company USA, web developer, web developer ahemdabad india, web developer india, Web development India, Word Press Reserch, Wordpress Customization Services, Wordpress Developer, Wordpress Developer India, wordpress freelance developer, wordpress freelance programmer, wordpress freelancer, Wordpress Freelancer India, Wordpress Programmer, Wordpress Shopping Cart, Wordpress theme customization, wordpress theme integration, x cart development india, x-cart Tags: , , , , , , , , , , , , , , , , , , , ,

Google new chart API

September 28, 2011 Leave a comment

Hi All,

 

A new API from Google that generates information charts in a dynamic way. its usage is quite straightforward: you link to an image in the form of a parameterized URL, such as http://chart.apis.google.com/chart?cht=p3&chd=t:90,49&chs=400×200&chl=data|bling.

“cht=p3? is the chart type, in this case, a pie chart.

 

“chd=t:90,49? are the chart values, text-encoded, and separated by a comma.

“chs=400×200? is the custom chart size, 400 by 200 pixels.

“chl=Data|Bling” are the different labels for the pie chart sections, separated via the pipe character.

chart types include: line charts, bar charts, pie charts, Venn diagrams & scatterplots.

View Demo

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Categories: Androide developer, CakePHP, CakePHP Developer India, freelance developer, Freelance PHP Developer, Freelance Programmer India, freelance web designer, Hire Dedicated Programmer, Hire Dedicated Programmer India, Hire PHP Developer India, Hire PHP Professional, Hire PHP Professional India, Hire PHP Programmer India, Hire Web developer, iphone application developer, iphone developer, iphone website designer, JavaScript, jquery, mysql, php, PHP Developer, PHP Developer India, PHP Development, PHP Freelance, PHP Freelancer, PHP Freelancer India, php freelancing india, php freelancing india mumbai, PHP programmer, PHP Programmer India, Php programming, tips & trics, url rewriting, web design india, web designer, web designer india, Web Developement Company USA, web developer ahemdabad india, web developer india, Web development India, Word Press Reserch, wordpress, Wordpress Blog Developer, Wordpress Customization Services, Wordpress Developer, Wordpress Developer India, wordpress freelance developer, wordpress freelance programmer, wordpress freelancer, Wordpress Freelancer India, Wordpress Programmer, Wordpress Shopping Cart, Wordpress theme customization, wordpress theme integration, x cart development india, x-cart Tags: , , , , , , , , , , , , , , , , , , , , ,

Submit Form Using Ajax (Post)

September 24, 2011 1 comment

Post.html

<script type="text/javascript" language="javascript">// <![CDATA[
var h_request = false;
function makePOSTRequest(url, parameters) {
h_request = false;

<!--more-->

if (window.XMLHttpRequest) //MOZILLA
{
h_request = new XMLHttpRequest();
if (h_request.overrideMimeType)
{
h_request.overrideMimeType('text/html');
}
}
else if (window.ActiveXObject) { // IE
try {
h_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
h_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!h_request) {
alert('Cannot create XMLHTTP instance');
return false;
}

h_request.onreadystatechange = alertContents;
h_request.open('POST', url, true);
h_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
h_request.setRequestHeader("Content-length", parameters.length);
h_request.setRequestHeader("Connection", "close");
h_request.send(parameters);
}

function alertContents() {
if (h_request.readyState == 4) {
if (h_request.status == 200) {
result = h_request.responseText;
document.getElementById('myspan').innerHTML = result;
} else {
alert('There was a problem with the request.');
}
}
}

function get(obj) {
var poststr = "mytextarea1=" + encodeURI( document.getElementById("mytextarea1").value ) +
"&mytextarea2=" + encodeURI( document.getElementById("mytextarea2").value );
makePOSTRequest('post.php', poststr);
}

// ]]></script>

<form action="javascript:get(document.getElementById('form1'));" name="form1" id="form1">
<textarea id="mytextarea1">testing data
1
2
3
</textarea>
<textarea id="mytextarea2">testing data 2
4
5
6</textarea>
<br>
<input type="button" name="button" value="Submit"
onclick="javascript:get(this.parentNode);">

</form>

<br><br>
Server-Response:<br>
<hr>
<span name="myspan" id="myspan"></span>
<hr>

Post.php

<?
print_r($_POST);
?>
Categories: ajax, Androide developer, CakePHP, CakePHP Developer India, freelance developer, Freelance PHP Developer, Freelance PHP Programmer, Freelance Programmer India, freelance web, freelance web designer, Freelance web developer, get a freelancer, Hire Dedicated Programmer, Hire Dedicated Programmer India, Hire PHP Developer India, Hire PHP Professional, Hire PHP Professional India, Hire PHP Programmer India, Hire Web developer, Hire Web Developer India, india web development, Indian Freelancer, iOS, ipad, iphone developer, JavaScript, joomla, joomla developer india, jquery, mysql, oscommerce Customization, oscommerce developer, php, PHP Freelancer, PHP Freelancer India, php freelancing india, php freelancing india mumbai, PHP programmer, PHP Programmer India, Php programming, PHP Web Development, php web programmer, web designer india, Web Developement Company USA, web developer, web developer ahemdabad india, web developer india, Web development India, Word Press Reserch, wordpress, Wordpress Blog Developer, Wordpress Customization Services, wordpress freelance developer, wordpress freelance programmer, wordpress freelancer, Wordpress Freelancer India, Wordpress Programmer, Wordpress Shopping Cart, Wordpress theme customization, wordpress theme integration, x cart development india Tags: , , , , , , , , , , , , , , , , , , , ,

Optimizing PHP Through Habits

September 23, 2011 Leave a comment

What has been a long interest of mine in writing simple, maintainable and secure (a.k.a. Good[tm]) code, has forked off the offspring of optimization.

There are nummerous discussions in the blogosphere about whether to use echo versus print, iffor() is faster than while(), etc. and though the gains are usually very small, I desided to add my thoughts to the debate.

I found an article on optimization through coding habits in Ilia Alshanetsky’s zend performance slides and decided to test some of the claims. My test machine is my MacBook Pro 1.83GHz w. 2GB RAM, MacOS X 10.4.9, Apache 1.3 and PHP 5.2 (with Xdebug 2.0). I also have lots of applications running.

  • Peter Bowyer claims that require_once() is 3-4 times slower than require(). Ilia also says they are bad. My testing reveals the exact opposite with an empty include file. Callingrequire_once() 10000 times in a for() loop with an empty file is 4x faster.
  • Ilia advises against using magic functions like __autoload() and __get(), but the advantage of __autoload() in particular is obvious in any large project and is used by many phpframeworks. My primitive testing, however, shows inverse results. With a simply autoload requiring a class and 10000 loops of new Foo() versus require_once('foo.php'); new Foo() shows that __autoload() is ~3.7 times faster. I saw no difference between real methods and __get(), although the logic inside __get() will add some overhead.
  • If a class method can be static, declare it static. Speed improvement is by a factor of 4. I get a 50% speed increase (614ms vs. 414ms with 100000 iterations).
  • Avoid function calls within for() loop control blocks. In for( $i=0; $i<count($x); $i++ )the count($x) is called at every iteration.
  • Always, always quote array keys. $row['id'] is way faster than $row[id]. Ilia says 700%, I say about 200%.
  • Avoid regex if possible. Use ctype_digit($foo); rather than preg_match("![0-9]+!", $foo);.
  • Get rid of ‘harmless’ error messages – they take time to generate and output. The error supression operator @ is slow, so avoid when possible. With error_reporting set to E_ALL | E_STRICT on my machine, doing echo $rows[id] 10000 times instead of echo $rows['id]takes 38 times longer.

     

    UPDATE: To summarize, this slow code runs in 500ms (although this time will vary a great deal depending on your error_reporting level):

     

     

     

     

    $rows = array_fill(0, 10000, array('id'=>0));
    require_once('foo.php');
    for( $i=0; $i < count($rows); $i++) {
        foo::notdeclaredstatic();
    
        $rows[$i][id] = 0;
    }
    
    
    
    
    By using the techniques above, it can be made to complete in 68ms:
    
    $rows = array_fill(0, 10000, array('id'=>0));
    function __autoload($classname) { require_once( 'foo.php'); }
    $size = count($rows);
    for( $i=0; $i < $size; $i++) {
        foo::declaredstatic();
    
        $rows[$i]['id'] = 0;
    }
    
    
    10000 iterations is a lot for one request to a page. Using the techniques, the code became roughly 7 times faster.
    
    I am not out to prove Ilia wrong - he knows PHP better than most - and 
    for all I know, they could have optimized those very functions in PHP 5.2. I am, however, 
    interested in seeing what can be done to optimize PHP performance simply by doing things differently,
    by tweaking one's coding style. It would appear that there are improvements, albeit small, to achieve 
    from minimal effort. Plus I was surprised by the discrepancies I found compared to Ilia's recommendations.
    
    

     

Timezones in MySQL and PHP

September 22, 2011 Leave a comment

Timezones in web applications are often dealt with the same way as character sets. Either incorrectly or ignored. The case of unicode is improving slowly as developers discover the need for international language support.
The problem with not handling timezones correctly is not apparent in the usual case of the webserver and the database server being in the same timezone. A lot of PHP code passes the task of timestamps on to MySQL, e.g. by calling NOW() on inserting or updating records. It is nessesary to know in what timezone the timestamps are stored to process them correctly.

Often a specific timezone is assumed for displaying date and time. This could very well be incorrect for a large number of visitors. If the database server is in yet another timezone, things begin to get out of sync.

MySQL’s handling of timezones is – obviously – separate from that of PHP. Along with the fact that the MySQL timezone can only be changed by users with SUPER privileges, this means that MySQL cannot be relied on for creation of timestamps in correct timezone. In other words, the usual call toNOW() is not an option.

PHP 5.1 introduced the date_default_timezone_set() method for setting the timezone PHP will use for functions like date() (or alternatively the date.timezone php.ini directive). This allows for a flexible and consistent way of creating timestamps in the correct timezone form within PHP. One user in London might start a thread while a response comes from New York. To handle this consistently and make sure both users see local time and the correct timespan between the posts, use date_default_timezone_set() to create the timestamps from PHP in a fixed timezone like GMT.

Time for an example to illustrate the practical use of this. I created a simple class Timer for dealing with these operations. The methods will be called statically as there is no need to instantiate the class.


class Timer 
{   
    static function DatetimeInGMT() {
        return date("Y-m-d H:i:s", time()-date("Z",time()));
    }

    static function GMTDatetimeToLocal($datetime) {
        $time = strtotime($datetime);
        return date("Y-m-d H:i:s", $time+date("Z",$time));
    }
}


Timer::DatetimeInGMT() produces a timestamp in GMT. I use it instead of MySQL’s NOW()because it calculates the time relative to the timezone set in PHP rather than that of MySQL.

When reading the timestamp back in to PHP, another function call is needed to convert it back to whatever timezone PHP is in at that time (it might be a different user viewing with another timezone setting). That’s the job of Timer::GMTDatetimeToLocal($datetime).

These two very simple functions and a correct setting of PHP’s timezone will ensure that dates are stored in a consistent way and displayed correctly.

 

 

%d bloggers like this: