Welcome to Abdul Malik Ikhsan's Blog

Practical GIT (2) : Update remote file after push with configure post-receive hooks

Posted in GIT, Teknologi by samsonasik on November 20, 2012

GIT version control got one feature that I really like, named hooks. With hooks, we can configure what GIT do after metadata pushed to the remote server. It can ease our development because we don’t need to upload file manually, just say : git push remoteserver, so the file in our online web will be replaced.

Continue Reading

Advertisements
Tagged with: , ,

Zend Framework 2 : Dynamic Navigation using Zend\Navigation

Posted in Tutorial PHP, Zend Framework 2 by samsonasik on November 18, 2012

Zend Framework 2 provide Navigation component to generate menu. It can utilize by creating static config in autoload/*.global.php. Sometime, we need dynamic menu to be generated in our application. I will give you a simple example to do that.
Continue Reading

Zend Framework 2 : Setting Default Db Adapter via Service initializers

Posted in Tutorial PHP, Zend Framework 2 by samsonasik on November 13, 2012

I just read very useful tutorial from akrabat site. He explain about Zend\ServiceManager configuration keys. And, the most I like is about service initializer. It can inject to all instance of something, for example, if Model is extends AbstractTableGateway.
For example, you have SampleTable class like the following :

class SampleTable extends AbstractTableGateway
      implements \Zend\Db\Adapter\AdapterAwareInterface 
{
    protected $table = 'sampletable';
 
    public function setDbAdapter(Adapter $adapter)
    {
        $this->adapter = $adapter;
        $this->resultSetPrototype = new HydratingResultSet();
        
        $this->resultSetPrototype->setObjectPrototype(new Sample());
        $this->initialize();
    }
}

So, you can initialize of instantiation of all class that implement AdapterAwareInterface like SampleTable.

class Module 
{
    public function getServiceConfig()
    {
	return array(
	    
	    'initializers' => array(
		function ($instance, $sm) {
		    if ($instance instanceof \Zend\Db\Adapter\AdapterAwareInterface) {
			$instance->setDbAdapter($sm->get('Zend\Db\Adapter\Adapter'));
		    }
		}
	    ),
            
            'factories' => array(
                'SampleModule\Model\SampleTable' =>  function($sm){
		    $table     = new Model\SampleTable();
		    return $table;
                },
            ),
            
       );
    }    
}

Easy setup, thanks Akrabat.

Reference :
http://akrabat.com/zend-framework-2/zendservicemanager-configuration-keys/