Saturday, December 21, 2013

What is Reflection in php and why it is use in real life oops

Reflection usually refers to accessing the definition of types and functions during runtime. It is most useful in static languages such as C# or Java, but I guess it could be useful in dynamic languages such as PHP too.

In PHP, it seems it can be used to retrieve documentation of existing classes/functions. But I don't think it will help you with writing documentation.
Reflection can be used for observing and/or modifying program execution at runtime. A reflection-oriented program component can monitor the execution of an enclosure of code and can modify itself according to a desired goal related to that enclosure. This is typically accomplished by dynamically assigning program code at runtime.
In object oriented programming languages such as Java, reflection allows inspection of classes, interfaces, fields and methods at runtime without knowing the names of the interfaces, fields, methods at compile time. It also allows instantiation of new objects and invocation of methods.

Reflection can also be used to adapt a given program to different situations dynamically. For example, consider an application that uses two different classes X and Yinterchangeably to perform similar operations. Without reflection-oriented programming, the application might be hard-coded to call method names of class X and class Y. However, using the reflection-oriented programming paradigm, the application could be designed and written to utilize reflection in order to invoke methods in classes X and Y without hard-coding method names. Reflection-oriented programming almost always requires additional knowledge, framework, relational mapping, and object relevance in order to take advantage of more generic code execution. Hard-coding can be avoided to the extent that reflection-oriented programming is used.

Reflection is often used as part of software testing, such as for the runtime creation/instantiation of mock objects.

Reflection is also a key strategy for metaprogramming.
The name reflection is used to describe code which is able to inspect other code in the same system (or itself).
For example, say you have an object of an unknown type in Java, and you would like to call a 'doSomething' method on it if one exists. Java's static typing system isn't really designed to support this unless the object conforms to a known interface, but using reflection, your code can look at the object and find out if it has a method called 'doSomething' and then call it if you want to.
So, to give you a code example of this in Java (imagine the object in question is foo) :
Method method = foo.getClass().getMethod("doSomething", null);
method.invoke(foo, null);
One very common use case in Java is the usage with annotations. JUnit 4, for example, will use reflection to look through your classes for methods tagged with the @Test annotation, and will then call them when running the unit test.
There are some good reflection examples to get you started athttp://docs.oracle.com/javase/tutorial/reflect/index.html
And finally, yes, the concepts are pretty much similar in other statically types languages which support reflection (like C#). In dynamically typed languages, the use case described above is less necessary (since the compiler will allow any method to be called on any object, failing at runtime if it does not exist), but the second case of looking for methods which are marked or work in a certain way is still common.
This group of classes was created for the express purpose of introspecting other classes. These classes make it possible to examine the properties of other classes by retrieving metadata about classes; you can even use them to examine the reflection classes themselves.
Reflection provides information about the modifiers of a class or interface—whether that class is final or static, for example.
It can also reveal all the methods and data members of a class and all the modifiers applied to them.
Parameters passed to methods can also be introspected and the names of variables exposed. Through reflection it is possible to automate the documentation of built-in classes or user-defined classes.
It turns out that the central repository of information about classes was right in front of us all the time. PHP can tell us all about itself through the mirror of the reflection classes.
The reflection group of classes or Application Programming Interface (API) is made up of a number of different classes and one
<?php
class HelloBikash{

    public function sayHelloTo($name) {
        return 'Hello ' . $name;
    }

}

$reflectionMethod = new ReflectionMethod('HelloBikash', 'sayHelloTo');
echo $reflectionMethod->invoke(new HelloBikash(), 'Mike');
?>
Reflection class are

Thursday, December 19, 2013

how to do replication using my mysql database my.ini configuration setup

As we know that MySQL replication works with binary log. Master create logs of the queries which made modification in database. And then master send event to the slave to execute that query. So on master server we need to setup binary log and also we can inform master server to create log for which database(the databases which we want to replicate).
In my case I have added following line in my master server my.ini file to start binary logging for database replication_test.
create log-bin directory if folder not available 
log-bin="C:/xampp/mysql/data/binlog/bin-log" #Specifing path to store binary log
log-bin-index=c:/xampp/mysql/data/bin-log-index #specify path to store binary log indexes
binlog-do-db=replication_test #Database for which binary log is enable.
server-id=1 #Server ID which is mandatory for replication

After specifying above setting in your master server please restart mysql service on your master server.
After restarting your master server please hit following query on your master :
show master status
If your query is giving following result then every thing is fine:
Master Replication StatusNow let us create a user on master server which will be used for the replication purpose. All you need to do here is to create a user and grant replication slave privileges to that user. You can do it using following query on master server
CREATE USER 'replication_user'@'%' IDENTIFIED BY 'replication';
GRANT REPLICATION SLAVE ON *.* TO 'replication_user'@'%';

Now almost you are done with the setting which is required on master server. Below steps are now for the setting of slave server. Let us jump to another server now.
Slave Server Setup: On slave first you need to mention your master server details in your my.cnf/my.ini
server-id=2 #Unique number like primary server
master-host=192.168.43.210 #IP of master server
master-user=replication_user #User we have created for the replication on slave
master-password=replication #Password of the userver
master-connect-retry=60   #retry time
replicate-do-db=replication_test #name of the database to be replicated.
Now after adding this configuration please make sure that your both server(master and slave) has same data for the database which you are going to replicate(in our case replication_test database). If your both server has identical data then you can restart your slave server after adding above configuration. Otherwise first make both master and slave identical and then restart your slave server.Now hit the following query on slave server:
SHOW SLAVE STATUS;
And if you are getting following result then every thing is fine and you did it:
+----------------------------------+----------------+------------------+-------------+---------------+-----------------+---------------------+-------------------------+---------------+-----------------------+------------------+-------------------+------------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
| Slave_IO_State | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File | Read_Master_Log_Pos | Relay_Log_File | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master |
+----------------------------------+----------------+------------------+-------------+---------------+-----------------+---------------------+-------------------------+---------------+-----------------------+------------------+-------------------+------------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
| Waiting for master to send event | 192.168.43.210 | replication_user | 3306 | 60 | bin-log.000043 | 106 | mysqld-relay-bin.000002 | 241 | bin-log.000043 | Yes | Yes | replication_test | | | | | | 0 | | 0 | 106 | 241 | None | | 0 | No | | | | | | 0 |
+----------------------------------+----------------+------------------+-------------+---------------+-----------------+---------------------+-------------------------+---------------+-----------------------+------------------+-------------------+------------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
To check the replication let us create a table on master server and see what is happening on slave server. I have used following query to create table on master server:
CREATE TABLE `replication_test`.`test`( `id` INT(11) NOT NULL AUTO_INCREMENT, `name` VARCHAR(255), PRIMARY KEY (`id`) );
Now I can see the same table created in the slave replication_test database. WOW!!!!!

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.

Tuesday, December 17, 2013

What is the use extract and compact function in php

A possible use for extract() is to import into the symbol table variables contained in an associative array returned by
<?php
/* Suppose that $var_array is an array returned from
   wddx_deserialize */
$size "large";$var_array = array("color" => "blue",
                   
"size"  => "medium",
                   
"shape" => "sphere");extract($var_arrayEXTR_PREFIX_SAME"wddx");

echo 
"$color$size$shape$wddx_size\n";
?>
The above example will output:

blue, large, sphere, medium
---------------------------------------------------------
compact — Create array containing variables and their values
Example #1 compact() example
<?php
$city  
"San Francisco";$state "CA";$event "SIGGRAPH";
$location_vars = array("city""state");
$result compact("event""nothing_here"$location_vars);print_r($result);?>
The above example will output:

Array
(
    [event] => SIGGRAPH
    [city] => San Francisco
    [state] => CA
)

Saturday, December 14, 2013

How I converted my HTML template into a Drupal 6 theme[Solved]

In my recent Boston Drupaltherapy workshop I got stuck on an in-class example of how to convert a well-formed HTML template into a Drupal 6 theme. I was showing this off as an example for how new Drupal users could attack themeing in a lightweigh way by using an HTML template as a starting point. I picked a simple HTML template that I found with a free license on a free HTML template site.

The excercise uses Drupal's core default theme called Garland and mercilessly steals portions of theme code from it to paste into the correct places in the new HTML template. I've got screenshots below that show the windows for Garland open right beside my HTML template window so I can make direct comparisons between the files and their contents.

Here is my original default theme and some sample content:


Here are the directories of each theme beside each other, Garland on left, Blackfairy on right:

First things first, in order for Drupal 6 to acknowledge and detect that my new theme Blackfairy exists, I have to move the HTML template into my sites/all/themes directory. New in Drupal 6, I also need to create a .info file that will tell Drupal information about this new theme - like theme name, blurb, version number and what theme engine it depends on. I simply created a new text file in my Blackfairy directory called blackfairy.info, and inserted this stuff:.

name = Blackfairy
description = A sexy little theme with a huge orange block and a large orchid, originally hacked from a free HTML template.
core = 6.x
engine = phptemplate

Now my new theme will register on the admin/build/themes page and I could enable and configure this theme. When I enable Blackfairy I get the HTML of the theme displayed on my Drupal pages, stripped of its CSS formatting, like this:

It looks like garbage because Drupal is looking inside the theme directory for files of certain names, and Blackfairy doesn't have those yet. We have to change Blackfairy's original index.html file into a file called page.tpl.php. Similarly, I changed Blackfairy's default.css file to style.css so it matches the naming convention Drupal likes for CCS files. We're starting to look more like a Drupal theme directory at this point:

From this point forward, it's a copy/paste marathon to replace the HTML elements of Blackfairy with the Drupal theme elements found in Garland. I simply compare the two page.tpl.php files side by side. There are about five simple copy/paste exercises that I'll do that will make my new theme come to life.

First, we can tell from the current state of our Drupal site that this Blackfairy theme can't find its CSS file. That makes sense because we changed the name of the CSS file in an earlier step. Lets solve this by stealing the contents of the head tags from Garland and inserting it into the matching tags in Blackfairy. This carries over the $head, $styles, $scripts into my new theme, reestablishing the calls for the CSS files (among other things).

Again, Garland is on the right, Blackfairy on the left. I have highlighted the swap I am about to do:

Second, I want to replace Blackfairy's title and slogan with corresponding values from our Drupal site. In this case, I am stealing the code inside Garland's header tags and inserting it into the matching tags in Blackfairy, and after doing this we can see that resulting page is showing us or first "Drupal-ish" theme elements - the title of our site rather than Blackfairy's hard coded title. Here are the changes:

Third, look inside the Blackfairy template and find the div called content and its enclosed divs called colOne and colTwo. Blackfairy is treating these two columns the way Drupal might present a main content area and a sidebar. Let's replace the contents of Blackfairy's colTwo with Garland's code for rendering the main content area called center. Look at the example replacement here:

The last theme template change I'll make is to carry over all the xx.tpl.php template files from Garland so that Blackfairy's theme can take more granular control over nodes, comments, blocks, etc. I'll also create a new, blank template.php file so that any future themers using Blackfairy can write in their custom theme functions there. I can just copy all these files from Garland directly:

The last steps I don't need to show you explicitly since the rest is CSS work to tweak your styles to match more closely those of the original Blackfairy. These were pretty lightweight changes just to show you how close I can get the styling in just a few minutes. I can also get into themeing the nodes, blocks or comments to help get closer to this design.

When it is all tweaked out, the result is a Drupal 6 theme built from a plain HTML/CSS design that could have been made by anyone without specific Drupal skills. The original HTML design has been very fairly replicated in this conversion, and it didn't take a CSS genius to do it. Here is the display of a fully converted Drupal 6 theme:

This Blackfairy theme was originally copyrighted under a Creative Commons license that isn't totally open source and prevents me from contributing this new Drupal 6 theme to Drupal.org, but it makes for an excellent teaching tool. Explore these examples of the original and the converted Blackfairy files to see the details of the changes that I made in this little exercise:

Blackfairy Original
Blackfairy Drupal 6

And by the way, for any of my students reading this, the reason why it wasn't coming together in the class was because of a cached blackfairy.info file that wasn't being cleared with the cache since I had been working on this same example the night before the class. There is a helpful description of .info files right here and what to do if you have been editing them and your theme doesn't render as expected.

Hope this helps someone out there. Good luck!:)

Multi language support translation wordpress plugin[Best One]

One of the best translation filter for WordPress offers a unique approach to blog translation. It allows your blog to combine automatic translation with human translation aided by your users with an easy to use in-context interface.
 67 languages are automatically translated for wordpress
  • Support for any language - including RTL/LTR layouts
  • Unique drag/drop interface for choosing viewable/translatable languages
  • Multiple options for widget appearances - with pluggable widgets and multiple instances
  • Translation of external plugins without a need for .po/.mo files
  • Automatic translation mode for all content (including comments!)
  • Professional translation bt One Hour Translation
  • Use either Google Translate,MS Translate or Apertium backends - 67 languages supported!
  • Automatic translation can be triggered on demand by the readers or on the server side
  • RSS feeds are translated too
  • Takes care of hidden elements, link tags, meta contents and titles
  • Translated languages are searchable
  • Buddypress integration
Download here hope you ejoy:)

Thursday, December 12, 2013

how to new module configure and run in ZF2 ?[Solved]

Guy you can download one module from here
how to run extracting the module?
Step 1->extract and copy in to C:\wamp\www\zf2crud\module then paste the module folder if(in case module name like  : (SanAuth-master remove to SanAuth)
Step 2->Go to C:\wamp\www\zf2crud\config\application.config.php
add the module :
  'modules' => array(
        'Application',
     'SanAuth'
    ),
last check the router url on location is C:\wamp\www\zf2crud\module\SanAuth-master\config\module.config.php
like :'router' => array(
        'routes' => array(
            
            'login' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/auth',
                    'defaults' => array(
                        '__NAMESPACE__' => 'SanAuth\Controller',
                        'controller'    => 'Auth',
                        'action'        => 'login',
                    ),
                ),
your browser url should be http://localhost/zf2crud/public/auth
lastly may help you :) enjoy :.............:)

Tuesday, December 10, 2013

insert and update with join and where cluse query in mysql[Solved]

Insert query example :
---------------------------
insert into cms_users(user_email,user_password,user_password_salt,user_activation_code,user_date_added)
select charity_contact_email,'25d896d7cb473deb61a752b845bdf548','WXaa','',now() from cms_charities
where charity_id in ( 
select charity_id  FROM cms_charities cc left join cms_users u on cc.charity_contact_email=u.user_email
where cc.charity_contact_email!='' and cc.charity_contact_email not in('sdowns@markomm.com','sarah.sievert@stbernardproject.org')
and u.user_email is null and cc.charity_submitted_by_user_id=0
)
Update query example :
-----------------------------
update cms_charities 
join cms_users
on cms_users.user_email=cms_charities.charity_contact_email
set cms_charities.charity_submitted_by_user_id=cms_users.user_id
WHERE cms_users.user_id>3367

Friday, December 6, 2013

how to install ZF2 on WAMP OR XAMPP guide follow these step for biggner

Easy step to install Zend Framewok 2(ZF2) follow below those step and enjoy
Step1-> install wamp or xampp but php should be install 5.3.3+

Setp-2>On  Apache mod_rewrite.so(remove #) location C:\wamp\bin\apache\Apache2.4.4\conf\httpd.conf

Sept-3> enable extension=php_curl.dll(remove ;) php.ini file
Note: Then restart your Apache server.

step 4->Download ZF2 library from http://framework.zend.com/downloads/latest

Extract and copy the only library folder paste into ZF2 skeleton location like :C:\wamp\www\skeleton\vendor\ZF2

step 5->Download  ZF2 skeleton from https://github.com/zendframework/ZendSkeletonApplication/

Lastly you can run your ZF2 in your localhost "hope help you"

http://127.0.0.1/skeleton/public/


i have already run, do not difficulty to face you  i think so :)

Wednesday, December 4, 2013

Upgrade PHP from version 5.2 to 5.x

The transition is not necessarily easy, but not hard also. PHP 5.3 brings some changes to the internal Zend API, so some PHP extension need to be upgraded (I had to upgrade xDebug). That means that you need to find the respective DLLs, which may not be that easy, depending on your current setup.
The config file, php.ini, is pretty much the same. You will actually have to take some things out actually (for example extension=php_pdo.dll is not needed anymore).
Just execute php -m from command line and see what errors are thrown. I have just copy-pasted the php.ini file from a 5.2 release and was done configuring 5.3 in a couple of minutes.
I mentioned xDebug a few lines above. If you use it, you should know that the line which activates xDebug is now:
zend_extension = "path\to\PHP 5.3.0\ext\php_xdebug.dll"
instead of:
zend_extension_ts = "path\to\PHP 5.3.0\ext\php_xdebug.dll"

OR other way to  Upgrading to PHP 5.X
If you take a look at Upgrading to PHP 5.3 - an easy way, i think that will solve your problem, but if you're in a Linux machine that you can use apt-get the only thing that you need to do is:
$ sudo apt-get upgrade php php-* mysql-*
$ /etc/init.d/httpd restart