Comments (10)
call? controller是一个类, 你找不到类call谁呢?
解决方案, 在ErrorController里面, 捕获CONTROLLER_NOT_FOUND异常, 执行你想要的代码
from yaf.
可能我没说明白,比方说,默认路由下,我访问/abc/def abc这个controller是存在的,只是没有defAction,但是我希望不报错,而是去调用 php的 _call()方法(类似wordpress插件的实现方式)。
from yaf.
我在abc这个controller里直接$this->defAction()时如果defAction不存在的话是可以直接调用__call方法的,但是通过网址访问则不行。
from yaf.
public function __call($method, $args) {
return do_action( $method , $args );
}
do_action是自己实现的一个函数。
from yaf.
hmm,明白了, 我想想, 目前肯定是不支持的
from yaf.
好……继续关注。谢谢
from yaf.
可以自己写路由.
在 2013-8-5 下午4:55,"Albert Lee" [email protected]写道:
好……继续关注。谢谢
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/50#issuecomment-22093967
.
from yaf.
有具体方案么?谢谢
from yaf.
from yaf.
thx
On Monday, August 5, 2013, lilj wrote:
之前写的, 你可以参考一下, 效率肯定不如鸟哥原生的,
request = $request; $uri = $request->getRequestUri(); $uri = preg_replace('/\/+/', '/', ltrim($uri, $request->getBaseUri())); $uri = preg_replace('/\?.*/', '', $uri); $uri = rtrim($uri, '/'); unset($_GET[$uri]); $this->params = $uri ? explode('/', $uri) : array(); $this->def = Yaf_Application::app()->getConfig()->application->dispatcher; $controller_prefix = $this->_findControllerPrefix(); $controller = $this->_findController($controller_prefix); $action = $this->_findAction($controller); $request->setControllerName($controller); $request->setActionName($action); $request->setRouted(TRUE); $request->setParam($this->params); return TRUE; } private function _findAction($controllerName){ if(isset($this->params[0])){ $action = strtolower($this->params[0]).YAF_SUFFIX_ACTION; if(method_exists($controllerName.YAF_SUFFIX_CONTROLLER, $action)){ return array_shift($this->params); } } return $this->defaultAction; } private function _findController($prefix){ if(isset($this->params[0])){ $controller = $prefix; $controller[] = ucwords($this->params[0]); $try_controller = implode('_', $controller); if($this->_isController($try_controller)){ array_shift($this->params); return $try_controller; } } $controller = $prefix; $controller[] = ucwords($this->defaultController); $try_controller = implode('_', $controller); if($this->_isController($try_controller)){ return $try_controller; } throw new Exception("Controller Not Found!"); } private function _findControllerPrefix(){ $controller_path = APP_PATH.'controllers'.DS; $prefix = array(); for($i = 0; $i < count($this->params);){ $controller_path = $controller_path.ucwords($this->params[$i]).DS; if(is_dir($controller_path)){ $prefix[] = ucwords(array_shift($this->params)); continue; } break; } return $prefix; } private function _isController($controllerName){ return Yaf_Loader::getInstance()->autoload($controllerName.YAF_SUFFIX_CONTROLLER); } } ?>
你可以尝试一下继承他的一些路由? 我没试过.Thanks
[email protected] <javascript:_e({}, 'cvml', '[email protected]');>2013/8/5 Albert Lee <[email protected] <javascript:_e({}, 'cvml',
'[email protected]');>>有具体方案么?谢谢
—
Reply to this email directly or view it on GitHub<
https://github.com/laruence/php-yaf/issues/50#issuecomment-22094204>
.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/50#issuecomment-22094576
.
李博
我们是搞开发的
http://t.sina.com.cn/1749026125?s=6uyXnP
from yaf.
Related Issues (20)
- Request::setControllerName 第二个参数format==false时 设置失败 HOT 1
- Yaf_Registry::set 的第二个参数为什么注释为 string 类型 HOT 1
- yaf model 的问题 HOT 2
- 开启公用类库后,无法使用composer HOT 2
- 偶发性问题Uncaught Error: Call to a member function run() on bool in ....../public/index.php HOT 1
- 希望鸟哥能增加一个配置用于控制是否开启默认路由. HOT 1
- yaf routing with namespace is on option HOT 4
- Fatal error: Class 'Yaf' not found HOT 2
- PHP8.2下 安装yaf-3.3.5报错 HOT 5
- Yaf_Config_Ini 造成 Too many open files 问题 HOT 3
- 使用了__get魔术方法后,当action不存在的时候,php进程会被直接终止,无法捕获错误。 HOT 4
- 支持phpstorm的代码查找
- v3.3.5 Yaf_View_Simple __isset bug
- fpm进程中存在多个application.ini文件句柄 HOT 3
- Error: Failed opening controller script
- PHP8.3 install yaf-3.3.5、yaf-3.3.4 extenstion error:make: *** [Makefile:209: yaf.lo] Error 1 HOT 2
- README.md contains outdated references to Travis CI service
- php-ext
- 使用 Yaf_Request_Http 对象的 getRequest(), getPost(), getQuery() 3个方法获取单个参数时候会导致程序中断
- 能否写个php 多线程处理的扩展啊。现在并发需求多。用户访问量大。
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yaf.