为Zend的table加上prefix

我不知道别人是怎么做的。我做的很累啊。。。明明在继承Zend_Db_Table_Abstract的类中打印getAdapter方法时,有_config变量,但是,它是protected的,没有找到合适的方法调用。
于是没办法。到bootstrap.php文件里加了一个方法。

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected $_bootConfig;

    public function  __construct( $application ) {
        parent::__construct($application);
        $this->_bootConfig = new Zend_Config_Ini( APPLICATION_PATH . '/configs/application.ini' );
        Zend_Registry::set('config', $this->_bootConfig);
    }
}

这样。我在bootstrap中也能直接使用 $this->_bootConfig 的变量。因为我使用了smarty,而且用的不是继承的方法。所以直接在__construct方法中把config变量赋值出来也有一定的方便之处。
就象这样:

    public function _initView()
    {
        require_once ('Smarty/Smarty.class.php');
        $tpl = new Smarty();
        $tplSettings = $this->_bootConfig->staging->smarty->toArray();
        foreach( $tplSettings as $key=>$value){
            $tpl->$key = $value;
        }
        Zend_Registry::set( 'tpl', $tpl);
    }

这样 _initView 之后,一定要在 application.ini里设置
resources.frontController.noViewRenderer = 1
不过这样就没有办法用zend_view的layout 。。。
于是我现在就在Zend_Db_Table_Abstract的继承类里用 init方法加了简单的处理

    public function init(){
        $config = Zend_Registry::get('config')->toArray();
        if(isset( $config['production']['resources']['db']['params']['prefix'] )){
            $prefix = strval( $config['production']['resources']['db']['params']['prefix'] );
            $this->_name =  $prefix . $this->_name ;
        }
    }

Over。解决。。。。

简单学习一下Zend_ACL

如果不想用rbac那么,简单权限管理ACL,应该是最方便的了。简要说一下原理吧。。
这个文件是放在/application/models/目录下的Acl.php,调用的时候就直接

$identity = Zend_Auth::getInstance()->getIdentity();
$acl = new Application_Model_Acl();
//然后判断
if( $acl->isAllowed( $identity['Role'] , 'xxxxx' ,'yyyy' )); //xxxx是controller名,yyyy是controller里的action名称。不用额外加action。。。
class Application_Model_Acl extends Zend_Acl
{

	public function __construct()
	{
		/*
		 *  第一次添加权限 "guest" ,支持查看所有的内容
		 */
		$this->addRole(new Zend_Acl_Role('guest'));

		/*
		 * 添加 'user' 组权限,权限大于 guest
		 * 用户组能够发表回复
		 */
		$this->addRole(new Zend_Acl_Role('user'), 'guest');

		/*
		 * 添加一个auth组
		 * auth用户权限基于user,并且可以发表文章
		 */
		$this->addRole(new Zend_Acl_Role('auth'), 'user');

		/*
		 * 添加admin组权限,可以做任何事情
		 */
		$this->addRole(new Zend_Acl_Role('admin'), 'blogger');

		//添加允许使用的Resource(也就是controller名啦),这是posts controller
		$this->add(new Zend_Acl_Resource('posts'));

		//添加允许使用的Resource(也就是controller名啦),这是comments controller
		$this->add(new Zend_Acl_Resource('comments'));

		//最后,添加权限,guest用户组可以执行posts controller下的view方法
		$this->allow('guest', 'posts', 'view');

		//User组可以执行 comments controller下的Add 方法
		$this->allow('user', 'comments', 'add');

		// auth 除了上面的功能外还能够支持 posts controller 中的Edit和add方法
		$this->allow('auth', 'posts', 'edit');
		$this->allow('auth', 'posts', 'add');
	}

}

是不是很方便?ACL就是这样的方便 。。