Mar
8
2015

How to reset drupal admin password with sql-query?

In Drupal 7, when you lost admin password and email notification cannot work, then you can reset drupal admin password with sql-query. For this you have to generate a password hash from following command.

Execute following command from command line, in Drupal root directory.

php .\scripts\password-hash.sh yourpassword

Note: If you get error that php is not recognized command then you need to set environment variable for php.

Note: change “yourpassword” with your desired password.

After this; execute the following query on drupal database.

UPDATE users SET pass = ‘$S$DkKBntGJ8OAHCyu.H9EYYRvokfk.Y8QjvpHI5FML1B7Okg0u970d’ WHERE uid = 1;

That’s it. Now you can login in your drupal admin with new password.


Jul
12
2014

How to execute jquery change function on page load?

In following code change function will trigger on page load because of change() it at end of function. This change() will make function to trigger on page load.

$("#select_drop_down").change(function(){
   ///// do some code here
}).change();


Jul
12
2014

How to show debug output in browser console in php?

While debugging php code we might need to use print_r() or var_dump() functions with exit or die, as in following code but by following code page will not render completely because exit or die stop remaining code from execution. If we don’t use die or exit then page design will break.

echo '<pre>';
print_r($debug_array);
echo '</pre>';
exit;

But we can also show debug output in browser console and page render completely without any break at same time. To do so following code will help to show output in browser console.

if(is_array($data) || is_object($data))
{
    echo("<script>console.log('".json_encode($data)."');</script>");
} else {
    echo("<script>console.log('".$data."');</script>");
}

Jul
12
2014

How to get controller name and method name in codeigniter?

Following codeigniter code is to get controller name and method name.

$this->router->fetch_class(); // class = controller
$this->router->fetch_method(); //

Jul
12
2014

Vim commands

Vim is a text editor written by Bram Moolenaar. Its based on the vi editor common to Unix-like system.

Following are commands for vi/vim.

Cursor movement

  • h – move left
  • j – move down
  • k – move up
  • l – move right
  • w – jump by start of words (punctuation considered words)
  • W – jump by words (spaces separate words)
  • e – jump to end of words (punctuation considered words)
  • E – jump to end of words (no punctuation)
  • b – jump backward by words (punctuation considered words)
  • B – jump backward by words (no punctuation)
  • 0 – (zero) start of line
  • ^ – first non-blank character of line
  • $ – end of line
  • G – Go To command (prefix with number – 5G goes to line 5)

Jul
12
2014

How to hide notices and warnings in php?

You can add following code on top of your php file. I had warnings and notices on joomla 2.5.11 site, I added following code in index.php file and it works.

ini_set('display_errors','off');

Feb
9
2014

doSelectStmt in symfony 1.2

doSelectStmt in symfony 1.2

        $cd = new Criteria();
        $cd->clearSelectColumns();
        $cd->addSelectColumn('SUM(' . TablePeer::QTY . ') as sumqty');
        $stmt = TablePeer::doSelectStmt($cd);
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
        echo $row['sumqty'];

Feb
9
2014

Run custom query in symfony 1.2 with propel

Sometimes we require to execute complex query in symfony 1.2 with propel. For this following code can be used.

$conn = Propel::getConnection();
$query = “Select  * from table”
$statement=$conn->prepare($query);
$statement->execute();
$rowObj = $statement->fetch(PDO::FETCH_OBJ);

$rowObj will have result of your given query. You can check it via var_dump or print_r and show it as you want.


Feb
2
2014

select all checkbox code in jquery

sometimes we have multiple checkbox fields in form and require to select all and deselect all. Following is code to select and deselect.

$("#selectAll").click(function(){
          $(".chkboxes").prop("checked",$("#selectAll").prop("checked"))
       }); 
       $(".chkboxes").click(function(){ 
        if($(".chkboxes").length == $(".chkboxes:checked").length) {
            $("#selectAll").prop("checked", true);
        } else {
            $("#selectAll").removeAttr("checked");
        }
       });

Feb
2
2014

referer redirect method in symfony.

$this->redirect($request->getReferer());

This is very useful method and used to redirect back to sender page.


Pages:12345678»

Hire Me!

Ads

affiliate_link

Ads