Saturday, 11 July 2015

[Solution] Unable to load or find PHP extension php_intl.dll in WAMP 0

Recently I was started to working with CakePHP 3.x. The latest version of CakePHP needed intl extension to work with it. But I could not enable intl extension in my latest version of Wamp 2.5. So, I have got an error,

PHP Startup : Unable to load dynamic library C:/wamp/path/to/php/ext/php_intl.dll - The specified module could not be found.

We can solve it in a two ways.

Solution 1:

  1. Just go to C:/wamp/path/to/bin/php/php5.5.12/. Copy all the files starts with icu* and paste it into C:/wamp/path/to/bin/apache/apache2.2.22/bin/  directory.
  2. To enable intl extension,
    • Click on the wamp icon
    • Click on PHP
    • Click PHP extensions
    • Click on php_intl
  3. Now Restart All Services. 
Thats all... Your intl extension is enabled now... 

Solution 2:

  1. Just include the PHP directory into the system's PATH variable.
  2. Install the full Microsoft VC++ 2012 Runtime Redistributable package. Make sure to get the 32 bit version for 32 bit PHP builds.
Have any doubt, feel free to comment here!

Friday, 3 July 2015

How to use plug-in's component in our application controller - CakePHP 3 0

Here is a small How to about creating and using plugin component in application controller.

Here we are going to create 'TestingComponent' inside of 'Test' plugin, Then get 'Hello world' text from component function and print it from our application's controller.

first create 'TestComponent' class in 'YourCakeDirectory\Plugins\Test\src\Controller\Component\TestComponent.php'

Here is the most important thing we have to do with our plugin load in CakePHP bootstrap. Before calling plug-in component in application controller, we need to auto load it in CakePHP. If our plugin created using bake method, we should autoload this class in 'composer.json'. If our plugin was manually created, then we should use 'autoload' parameter as a value 'true' as a configuration parameter while loading this plugin in application's 'YourCakeDirecctory\Config\bootstrap.php'.
The bellow one is a way to load component in controller on the fly.
Now we are going to load plugin's component. So we need to use our plugin component name followed by plugin name and dot('.'). Here we are going to load 'TestingComponent' from the plugin 'Test'. So, the code will be like the bellow,

Now we will get the output of plugin's component string 'Hello World' which is echoed from our application's controller.

Have any doubt, feel free to comment here!

Monday, 4 May 2015

How to get relative path in javascript 0

Problem

We can't easily get relative paths in javascript as like server side scripts. We have use our own logic to get it. Hard coding server root path in javascript is really bad idea. So, We are going to get our server root path from already loaded resource.


Why I need this?

If you are going to do use redirection or want to load any other resource which is located another directory in your server root directory, you may need server root path. On that time you should need this.

Solution

 Assume, we are having "http://sampledomain.com" and our assets in webroot directory. consider we have an external javascript file called "sample.js", add id attribute to your script tag.

And simply get the location of your javascript file during run time using javascript by parsing the DOM for the 'src' attribute that referred it:

Now we can call getRootPath() function to get the server root path. So, by our example our javascript function getRootPath() will return "http://sampledomain.com"

We can also use this as webroot path by removing "webroot" string from the replace function. If we did this, we will get "http://sampledomain.com/webroot" from the returned string.


Have any doubt, feel free to comment here!

Thursday, 26 February 2015

How to get sql dump using command prompt in WAMP 0

To get a mysql dump of a database in wamp, first we need to set our mysql path using set path command. The example is given below.
  

set path=c:\wamp\bin\mysql\mysql5.1.36\bin

Replace c:\wamp\bin\mysql\mysql5.1.36\bin with your mysql bin directory path.

Then use the below command to export our database.
 
mysqldump -u YourUserName -p YourDatabaseName > sqlDumpFileName.sql

YourUserName will be our mysql username. And YourDatabaseName will be our DataBase name. Then command prompt will ask for the mysql password. Your should enter your mysql password to get your sql dump of your database.

Have any doubt, feel free to comment here!