MasterSlaveFeature How-To

早过忘川 提交于 2019-12-05 02:06:10

问题


I currently have my Db Models using AbstractTableGateway and all my select/insert/update/delete queries are working just fine. But now I would like to add the MasterSlaveFeature and I'm a bit confused on how to do this. The documentation doesn't exactly give a good example:

http://zf2.readthedocs.org/en/latest/modules/zend.db.table-gateway.html#tablegateway-features

I currently have this setup:

namespace Login\Model;

use Zend\Db\TableGateway\Feature\MasterSlaveFeature;
use Zend\Db\TableGateway\Feature\FeatureSet;
use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Sql\Select;
use Zend\Db\Sql\Expression;

class Passport extends AbstractTableGateway
{
public function __construct($adapter, $slave)
{
    $this->table = 'passport';

    $this->adapter = $adapter;

    $this->featureSet = new FeatureSet();
    $this->featureSet->addFeature(new MasterSlaveFeature($slave));

    $this->initialize();
}

public function Profile($employeeid)
{
    $result = $this->select(function (Select $select) use ($employeeid) {
        $select
            ->columns(array(
                'count' => new Expression('COUNT(*)'),
                'employeeid',
                'passwd',
                'group',
                'name',
                'status',
                'timezone',
                'timeformat',
                'locale',
                'max_search'
            ))
            ->where($this->adapter->getPlatform()->quoteIdentifier('employeeid') . ' = ' . $this->adapter->getPlatform()->quoteValue($employeeid))
            ->limit(1);
    });

    return $result->current();
}

}

I am passing two Adapters $adapter and $slave, each have the same Tables, except one is empty and the other actually has data. Based on the documentation what I have should work, but I feel like I am missing something here, but don't know what.

The $adapter is the master database which has the data The $slave is the slave database which has no data

I would like my SELECTS to take the data from the $slave (which currently has no data) and Insert/Update/Delete should go to the $adapter.

Can someone help me figure this out? Thank you


回答1:


UPDATE: As of ZF 2.0.5 there is a bug. The configuration is correct.

UPDATE: Looks like this should be resolved in the 2.1 release

UPDATE: I can now confirm this is resolved and working in 2.0.7 and 2.1



来源:https://stackoverflow.com/questions/13674199/masterslavefeature-how-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!