yaf icon indicating copy to clipboard operation
yaf copied to clipboard

yaf 在Bootstrap中更改默认的模块不生效,更改默认控制器是生效的。

Open fangwChina opened this issue 7 years ago • 5 comments

class Bootstrap extends Yaf_Bootstrap_Abstract{

public function _initConfig() {
	//把配置保存起来
	$arrConfig = Yaf_Application::app()->getConfig();
	Yaf_Registry::set('config', $arrConfig);
}

public function _initPlugin(Yaf_Dispatcher $dispatcher) {
	//注册一个插件
	$objSamplePlugin = new SamplePlugin();
	$dispatcher->registerPlugin($objSamplePlugin);
}
public function  _initDefaultName(Yaf_Dispatcher $dispatcher){
	//配置默认路由[setDefaultModule 不生效]
	$dispatcher->setDefaultModule("Api")->setDefaultController("index")->setDefaultAction("index");
}
public function _initRoute(Yaf_Dispatcher $dispatcher) {
	//在这里注册自己的路由协议,默认使用简单路由
}

public function _initView(Yaf_Dispatcher $dispatcher){
	//在这里注册自己的view控制器,例如smarty,firekylin
}

} 结果如下: image

fangwChina avatar Aug 30 '17 06:08 fangwChina

我是直接在config文件里配置多节点,不同模块不同节点设置

WuJiY avatar Sep 18 '17 04:09 WuJiY

你是否在application.modules中配置了默认模块?

setDefaultModule:

/** {{{ proto public Yaf_Dispatcher::setDefaultModule(string $name)
*/
PHP_METHOD(yaf_dispatcher, setDefaultModule) {
	zval *module;
	zval *self = getThis();

	if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &module) == FAILURE) {
		return;
	}

	if (IS_STRING == Z_TYPE_P(module) && Z_STRLEN_P(module)
			&& yaf_application_is_module_name(Z_STR_P(module))) {
		zval module_std;
		ZVAL_STRING(&module_std, zend_str_tolower_dup(Z_STRVAL_P(module), Z_STRLEN_P(module)));
		*Z_STRVAL(module_std) = toupper(*Z_STRVAL(module_std));
		zend_update_property(yaf_dispatcher_ce, self, ZEND_STRL(YAF_DISPATCHER_PROPERTY_NAME_MODULE), &module_std);
		zval_ptr_dtor(&module_std);

		RETURN_ZVAL(self, 1, 0);
	}

	RETURN_FALSE;
}

其中调用了yaf_application_is_module_name函数验证module是否在application.modules配置中。

owenliang avatar Sep 28 '17 05:09 owenliang

头像不错

motecshine avatar Sep 28 '17 06:09 motecshine

楼上你关注点不一样啊

lagolas avatar Nov 16 '17 04:11 lagolas

https://github.com/letwang/HookPHP/blob/master/README.md 最好的是多域名绑定多模块 而不是强制切换

server {
	listen 80;
	root /home/letwang/workspace/HookPHP/public/admin/;
	index index.html index.htm index.php;
	error_log /var/log/nginx/www.admin.com-error.log error;access_log /var/log/nginx/www.admin.com-access.log combined;
	server_name www.admin.com;

	if (!-e $request_filename) {rewrite ^/(.*)  /index.php?$1 last;}

	location ~ \.php$ {
	       fastcgi_pass   127.0.0.1:9000;
	       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
	       include        fastcgi_params;
	 }
}

server {
	listen 80;
	root /home/letwang/workspace/HookPHP/public/erp/;
	index index.html index.htm index.php;
	error_log /var/log/nginx/www.erp.com-error.log error;access_log /var/log/nginx/www.erp.com-access.log combined;
	server_name www.erp.com;

	if (!-e $request_filename) {rewrite ^/(.*)  /index.php?$1 last;}

	location ~ \.php$ {
	       fastcgi_pass   127.0.0.1:9000;
	       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
	       include        fastcgi_params;
	 }
}

server {
	listen 80;
	root /home/letwang/workspace/HookPHP/public/paas/;
	index index.html index.htm index.php;
	error_log /var/log/nginx/www.paas.com-error.log error;access_log /var/log/nginx/www.paas.com-access.log combined;
	server_name www.paas.com;

	if (!-e $request_filename) {rewrite ^/(.*)  /index.php?$1 last;}

	location ~ \.php$ {
	       fastcgi_pass   127.0.0.1:9000;
	       fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
	       include        fastcgi_params;
	 }
}

letwang avatar Dec 06 '18 01:12 letwang