Thursday, November 5, 2015

After import sample data 1.9.1.0 can't login admin, no admin user in database?

Run this code in query:
LOCK TABLES `admin_role` WRITE , `admin_user` WRITE;

SET @SALT = "rp";
SET @PASS = CONCAT(MD5(CONCAT( @SALT , "password") ), CONCAT(":", @SALT ));
SELECT @EXTRA := MAX(extra) FROM admin_user WHERE extra IS NOT NULL;

INSERT INTO `admin_user` (firstname,lastname,email,username,password,created,lognum,reload_acl_flag,is_active,extra,rp_token_created_at) 
VALUES ('Firstname','Lastname','email@example.com','myuser',@PASS,NOW(),0,0,1,@EXTRA,NOW());

INSERT INTO `admin_role` (parent_id,tree_level,sort_order,role_type,user_id,role_name) 
VALUES (1,2,0,'U',(SELECT user_id FROM admin_user WHERE username = 'myuser'),'Firstname');

UNLOCK TABLES;
In admin site:
username: myuser
password: password 

Magento

https://en.wikipedia.org/wiki/Magento

Tuesday, October 27, 2015

Sunday, October 25, 2015

Codeigniter - The best practice in _remap() function

Instead of using like this:

function _remap($method)
{
         $array = array('method1','method2','method3','method4','method5','method6','method7',...);
         in_array($method, $array) ? $this->method() : $this->index()
}


to


function _remap($method)
    {
        $arr_raw_method_registered = get_class_methods(__CLASS__);
        $arr_remove_element = array('get_instance');
        $arr_method_registered = array_filter($arr_raw_method_registered, function($item)use($arr_remove_element) 
        {
            if (in_array($item, $arr_remove_element) || $item[0] == '_'):
                return false; 
            else:
                return true;
            endif;
        });
        
        in_array($method, $arr_method_registered) ? $this->$method() : $this->index();
    }

The function covers all defined function on that class.



Monday, October 19, 2015

Regex to Catch image in img tag

<img .*?src="[^"]*\/\K([^"]*?\.(?:jpeg|jpg|bmp|gif|png))