Thursday, December 19, 2013

what does return $this mean in php oops ?


This way of coding is called fluent interfacereturn $this returns the current object, so you can call multiple function as single object/line
code like this: do you know about method chaining if no ,then you can find here :)
$object
  ->function1()
  ->function2()
  ->function3()
  ;
instead of:
$object->function1();
$object->function2();
$object->function3();
Here is you can find real example 
<?php

class a{
    public $name='';
    public function setName($name){
        
        $this->name=$name;
        return $this;
    }
      public function getName(){
        
        $this->name;
        return $this;
    }
}


?>
Create an object to call method-chaining
<?php
$obja=new a();
$name=$obja->setName('bikash')->getName();
echo $name->name;
Hope this class may help you :)

Wednesday, December 18, 2013

how to send data using ajax jquery into createsend.com newsletter subscriber api[SOLVED]

I have seen the ajax form in the blogs, but to use that verbatim would require recoding the form itself everywhere it appears on our website.  So I am hoping to be able to use a modified version of our current ajax/jquery setup, so that I only need modify one master js file.I have included our code below.  The function works fine for submitting the subscription request and the new subscriber gets their reconfirm email ... however the success function is not working.Any ideas from the API gurus as to how I might get some success with the success?



var dataString = "cm-name="+newsfirstname+"&cm-tyhuly-tyhuly="+newsemail;
$.ajax({
   type: "GET",
   url: "http://bikashnews.createsend.com/t/j/s/tyhuly/",
   data: dataString,
   dataType: 'jsonp',
   success: function(data) {
    if (data.Status === 400) {

     alert('gettting errror');
    } else { // 200
     alert('successfully subscriber');
    }
   }
  });
dataType: jsonp for cross-domain request, that means request to different domain and dataType: json for same domain-same origin request.

Loads in a JSON block using JSONP. Adds an extra "?callback=?" to the end of your URL to specify the callback. Disables caching by appending a query string parameter, "_=[TIMESTAMP]", to the URL unless the cache option is set to true.