Tuesday 30 June 2015

Using multiple database connections in CakePHP model

Hello Readers,

Till now we may develop our application with single database . Is their any ways to integrate our application with multiple databases ? . Yes we have. There are methods to use multiple databases for development and for production without changing anything but rewriting a function in DATABASE_CONFIG class. Just open your database.php file inside config folder and search this class "DATABASE_CONFIG". Here you can add multiple database configuration.
  1. class DATABASE_CONFIG {
  2. public $default = array(
  3. 'datasource' => 'Database/Mysql',
  4. 'persistent' => false,
  5. 'host' => 'localhost',
  6. 'login' => 'username',
  7. 'password' => 'password',
  8. 'database' => 'database1',
  9. 'prefix' => '',
  10. //'encoding' => 'utf8',
  11. );
  12. public $test1 = array(
  13. 'datasource' => 'Database/Mysql',
  14. 'persistent' => false,
  15. 'host' => 'localhost',
  16. 'login' => 'username',
  17. 'password' => 'password',
  18. 'database' => 'database2',
  19. 'Prefix PHP' => '',
  20. //'encoding' => 'utf8',
  21. );
  22. public $test2 = array(
  23. 'datasource' => 'Database/Mysql',
  24. 'persistent' => false,
  25. 'host' => 'localhost',
  26. 'login' => 'username',
  27. 'password' => 'password',
  28. 'database' => 'database3',
  29. 'prefix' => '',
  30. //'encoding' => 'utf8',
  31. );
  32. }
The default database is "public $default" , if you want to use database2 you have to initialize "public $test 1" in your Model.

Open your UserModel.php
 
For further queries or PHP Programming Questions and Answers you can Visit to our PHP Developer Forum
 

Monday 29 June 2015

How to create a custom error page

In Cakephp we have some default error pages but we can create our own error page. Here we will create a custom error page to show error if controller not found. If controller not found then we will show 404 error page. Below are few steps for creating custom error page First create a error.ctp file for layout if you want to show error page with different UI Open appController.php under /app/Controller and add the below code
  1. function beforeRender() {
  2. $this->setErrorLayout();
  3. }
  4. function setErrorLayout() {
  5. if ($this->name == 'CakeError') {
  6. $this->layout = 'error';
  7. }
  8. }
- See more at: http://findnerd.com/list/view/How-to-create-a-custom-error-page/3470/
For any issue about PHP Programming Questions and Answers you can Visit to our PHP Developer Forum

Friday 26 June 2015

Get Instant Solutions to PHP Programming Problems

Hi Guys,








Do you have any PHP Programming Question and Answers Or Stuck in a PHP Language Issue? Just visit FindNerd Community Forum and get answers to all your PHP Language Queries on PHP Developer Forum. In this video blog, I am going to explain, how you can solve your PHP Programming Language issues. This forum is specially developed for those fellow programmer who got stuck in an issue and want an instant solution to their query.


The motive of this community is to save time for web developers during their web development project when they got stuck in any issue. Through this video, you will get to know about PHP Developer Forum where you can post your PHP Programming Queries and get instant replies from the highly experienced tech experts. The plus point of this community forum is its special feature of desktop recording that allow the users to explain their PHP Language Programming Question in an easy manner. Also you don't have to wait for long hours to get a solution, as the skilled tech experts answer the query within 2 hours.


Please view this blog and know the process how you can ask & resolve your PHP programming questions easily.



- See more at: http://findnerd.com/list/view/Get-Instant-Solutions-to-PHP-Programming-Problems/3526/

Wednesday 24 June 2015

Add prefix to urls in CakePHP

CakePHP has power to do a lot with conventions by using routes. It’s additionally possible to utilize custom prefixes adjacent to your admin routes for extra flexibility. Prefix routing can be enabled from within the core configuration file by setting the prefixes with Routing.prefixes.

Configure::write('Routing.prefixes',array('admin'));

We can create our prefix route as follows:

Router::connect('/employer/:controller/:action/*', array('prefix' => 'employer', 'employer' => true));


- See more at: http://findnerd.com/list/view/Add-prefix-to-urls-in-CakePHP/3553/


For queries about PHP Programming Questions and Answers

You can Visit to: PHP Developer Forum    

Monday 22 June 2015

Visibility Scope Of Variable And Functions -FindNerd

There are three type of visibility scope:
  • Public
  • Private
  • Protected
PUBLIC: Variable or function of public scope can be accessed throughout the program.  

PRIVATE : Variable or function of private scope can be accessed only with in the class they are declared.  

PROTECTED:
Variable or function of protected scope can be accessed only by its subclass and derived class.
 
 
<?php
/**
* Define ClassA
*/
class ClassA
{
public $a = 1;
protected $b = 2;
private $c = 3;
function detail()
{
echo $this->a;
echo $this->b;
echo $this->c;
}
}
$obj = new ClassA();
echo $obj->a; // Works
echo $obj->b; // Fatal Error
echo $obj->c; // Fatal Error
$obj->detail(); // Shows Public, Protected and Private
 
 
Variable or function of protected scope can be accessed only by its subclass and derived class.

 - See more at: http://findnerd.com/list/view/Visibility-Scope-Of-Variable-And-Functions/3556/

For queries about PHP Programming Questions and Answers

You can also Visit to PHP Developer Forum  

Friday 19 June 2015

Google Map integration in PHP to Calculate Latitude and Longitude

This code will calculate the latitude and longitude of the place in background on entering the place name.

For integration of Google map to calculate Latitude and Longitude major script is :
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>


To make the autocomplete of the address create a object of the class:

google.maps.places.Autocomplete
 

Here is the complete code to get the exact location latitude and longitude using Google map. Hope it may help you somewhere.

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script>
<script type="text/javascript">
function initialize() {
var address = (document.getElementById('my_address'));
var autocomplete = new google.maps.places.Autocomplete(address);
autocomplete.setTypes(['geocode']);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
var place = autocomplete.getPlace();
if (!place.geometry) {
return;
}
 
 
- See Full Code at: http://findnerd.com/list/view/Google-Map-integration-in-PHP-to-Calculate-Latitude-and-Longitude/3558/



For queries about PHP Programming Questions and Answers, You can also Visit to PHP Developer Forum    

Wednesday 17 June 2015

C Developer Forum for Programming Questions and Answers

Hello Nerds,

In this video blog, you will get to know how you can get rid of C Programming Questions & Language issues. I have seen many programmers who get stuck in C Programming queries during the Web Development Projects and wasted their whole day while exploring for the correct solution.



 C-Developer-Forum-for-Programming-Questions-and-Answers 


Through this video, I am introducing a powerful C Developer Forum where you can post your C programming questions and answers. Get instant reply from the highly experienced community members. The best part of this community forum is that you don't have to struggle and wait for long hours to get a solution, as the skilled tech experts are online and will answer your query within 2 hours.


 - See more at: http://findnerd.com/list/view/C-Developer-Forum-for-Programming-Questions-and-Answers/3507/