Posts

Showing posts from November, 2012

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.