Posts

Showing posts from 2012

apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

Problem: user@localhost:~$ sudo service apache2 restart  * Restarting web server apache2                                               apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName  ... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName Solution: Open and edit your apache2.conf       sudo gedit /etc/apache2/apache2.conf Into the file write:        ServerName localhost Save the file. Restart your apache.     sudo service apache2 restart   

The requested URL /phpmyadmin was not found on this server.

Problem: localhost/phpmyadmin   Not Found The requested URL /phpmyadmin was not found on this server. Apache/2.2.22 (Ubuntu) Server at localhost Port 80       Solution: PhpMyAdmin, by default, writes an alias in a file /etc/phpmyadmin/apache.conf   Open and edit your apache2.conf       sudo gedit /etc/apache2/apache2.conf Into the file write:        Include /etc/phpmyadmin/apache.conf Save the file. Restart your apache.     sudo service apache2 restart 

CakePHP : Accessing the logged in user

Once a user is logged in, you will often need some particular information about the current user. You can access the currently logged in user using  AuthComponent::user() . This method is static, and can be used globally after the AuthComponent has been loaded. You can access it both as an instance method or as a static method: You can access all the user's information(fields) from the users table except the password. <?php // Use anywhere  // Accesing user’s id AuthComponent :: user ( 'id' );                                                                 $_SESSION[' Auth '][' User' ][' id ']; // Accesing user’s username AuthCompo...

CakePHP: GET Current Controller, Action and Parameters

Image
We will have the following url:                       http://developerguides.blogspot.com/users/view/1/2/3 To get the current controller:                       echo $this ->params[ 'controller' ]; Output:         users To get the current action:                       echo $this ->action; Output:         view To get the first parameter:                       echo $this ->params[ 'pass' ][0]; Output:         1 To get the second parameter:...

Convert the first character to upper case in php

Capitalize first letter of the string of a word or sentence by using ucfirst() function. Capitalize first letter of every word  in a sentence by using ucwords() function. <?php $string = " convert the first character to uppercase in PHP. " ; $title = ucwords ( $string ); echo $title . " \n " ; $sentence = ucfirst ( $string ); echo $sentence ; ?> Output: Convert The First Character To Uppercase In PHP. Convert the first character to uppercase in PHP.

CakePHP : Filter dropwdown list

Image
Controller: $contactGroups=$this->Contact->ContactGroup->find('list',                             array('fields'=> array('group_name'), //field to be displayed in dropdown                             'conditions'=>array('user_id'=>$this->Auth->User('id') //filtered by user_id                                                                           ))); $this->set(compact('contactGroups'));

Using multiple database in CakePHP 2.2.2

Image
Edit your app/Config/database.php class DATABASE_CONFIG {     public $default = array(         'datasource' => 'Database/Mysql',         'persistent' => false,         'host' => 'localhost',         'login' => 'username1',         'password' => 'password1',         'database' => 'databasename1',         'prefix' => '',         //'encoding' => 'utf8',     );     public $sms_gateway = array(         'datasource' => 'Database/Mysql',         'persistent' => false,         'host' => '192.168.1.1',         'login' => 'username2',     ...

PHP : Write a file on a remote server via ssh

<?php //remote server address $remote_ip = '192.168.1.1'; $port = '80'; //login account $username = 'yourusername'; $password = 'yourpassword'; //ssh connection $connection = ssh2_connect($remote_ip, $port); ssh2_auth_password($connection, $username, $password'); $sftp = ssh2_sftp($connection); $remote_dir = '/var/www/'; $the_msg = 'I am creating and writing in a file on a remote server via ssh"; $stream = @fopen("ssh2.sftp://".$sftp.$remote_dir, 'w+'); if (fwrite($stream, $the_msg) == false){           echo "Could not write data"; } //close connection fclose($stream); ?>

PHP - Call to undefined function ssh2_connect

Error: Call to undefined function ssh2_connect() Steps for installing the extension package on (Ubuntu) Debian systems: > sudo apt-get install libssh2-php Restart APACHE to take effect > sudo /etc/init.d/apache2 restart

ACL Plugin for CakePHP 2.0

Image
This plugin is such an interface allowing to manage permissions of your application's users and roles. 1. Download latest CakePHP latest stable in CakePHP.org. 2. Install CakePHP see how: Install CakePHP 2.x in Ubuntu. 3. Setup a Simple Acl Controlled Application follow instruction here : Simple  Acl Controlled Application , part 1 only. 4. Download ACL Plugin for CakePHP 2.1 ACL Plugin Installation copy the folder acl in your folder /app/plugins configure the admin route (see http://book.cakephp.org/2.0/en/development/routing.html#prefix-routing ) copy the parameters found in Acl/Config/bootstrap.php in your file /app/Config/bootstrap.php or load the plugin with its own bootstrap.php file ( CakePlugin::load('Acl', array('bootstrap' => true)); ) see more: ACL Plugin Installation  5. In your bootstrap.php located in your cakefolder/app/Plugin/Acl/Config/bootsrap.php. If you use groups (if you use database in in simple acl controlled ap...

CakePHP 2.x : Bake in Ubuntu

Image
Before we bake, you should have finished installing CakePHP and created your database. 1. Open your terminal. You must change your directory to your cake. Type:           cd /var/www/cakefolder/app           Console/cake bake Your CakePHP v2.x Console will display. Next process is the same with CakePHP 1.3, follow step 4 here .

Install CakePHP 2.x in Ubuntu

Image
 Requirements: HTTP Server. For example: Apache. mod_rewrite is preferred, but by no means required. PHP 5.2.8 or greater. Download CakePHP 2.x at their website: http://cakephp.org/ Extract your downloaded file. Copy and paste the contents of the Cake archive in /var/www/cakephp Make it writable, open your terminal and type: sudo chmod 777 -R /var/www/cakephp Create database. Goto /var/www/cakephp/app/Config/ and rename your database.php.default to database.php. Open database.php, then just replace the values in the $default array with those that apply to your setup. . A sample completed configuration array might look something like the following: <?php public $default = array ( 'datasource' => 'Database/Mysql' , 'persistent' => false , 'host' => 'localhost' , 'port' => '' , 'login' => 'DatabaseUsername' , 'password' ...

CakePHP 1.3 : Bake in Ubuntu

Image
Before we bake, you should finished installing CakePHP and created your database. 1. Open your terminal. You must change your directory to your cake. 2. To open cake type: 3. Supply your password. 4. Whoola! This is your CakePHP Console.   5. The first thing we should bake is the Model. Type m then hit enter. We will use default database config so hit enter again. 6. The tables name of your database will be displayed. In CakePHP table name must end with ” s “. We will choose users. 7. I will pass displayfield and validation here, but you may explore it. Since my users table is associated with other table I type ” y “. My model users already exist and was detected by the CakePHP and so I just overwrite it. 8.  Next, lets bake Controller.  Type in ” c ” then hit enter. We will use default database config. 9. We will use users table again. If you like to build your user controller at one time (index(), add(), edit(), delete()), don’t...

Pop up Window

Add this javascript code in your html. window.open("Page","Window Name",  "menubar=no,width=430,height=360,toolbar=no"); Button     <input type="button" name="pop" value="Click to Pop" onClick =  window.open(" http://developerguides.blogspot.com/ ","Pop1",  "menubar=no,width=500,height=600,toolbar=no"); > Option Values Description Version location yes|no Does the location bar show? ver 1.0 menubar yes|no Does the menubar show? ver 1.0 scrollbars yes|no Do scrollbars show? ver 1.0 status yes|no Does the status bar show| ver 1.0 titlebar yes|no Does the titlebar show? ver 1.0 toolbar yes|no Does the toolbar show? ver 1.0 resizable yes|no Can you resize the window? ver 1.0 height pixels height of window ver 1.0 width pixels width of window ver 1.0 directories yes|no Does the personal toolbar show? ver 1.2 innerHeight pixels specifies the inner height of window ver...