public function indexAction() { $request = new Yaf_Request_Http(); if ($request->isGet()) { return; } if ($request->isPost()) { $post = $request->getPost(); $username = $post['username']; $password = $post['password']; if ($username == 'admin' && $password == 'admin') { Yaf_Session::getInstance()->offsetSet('username', $username); $this->redirect("Admin"); // 跳转到login Actios->forward("login", array("from" => "Index")); // 跳转到login Action return FALSE; } else { $password = md5($password); $sql = 'SELECT * FROM user WHERE username=:username AND password=:password'; $stmt = $this->dbo->prepare($sql); $stmt->bindValue(':username', $username); $stmt->bindValue(':password', $password); $stmt->execute(); $rows = $stmt->fetch(); if (empty($rows)) { echo "用户名或密码错误"; } else { Yaf_Session::getInstance()->offsetSet('username', $username); Yaf_Session::getInstance()->offsetSet('userid', $rows['id']); $this->redirect('Admin'); return; } } exit; } }
public function onRequest($request, $response) { $response->status('200'); $ser = $request->server; $hea = $request->header; $hea['host'] = str_replace(':9501', '', $hea['host']); //如果端口号是80,就不用要此句代码 ob_start(); try { $yaf_request = new Yaf_Request_Http($ser['request_uri']); $yaf_request->setBaseUri($hea['host']); $this->application->getDispatcher()->dispatch($yaf_request); } catch (Yaf_Exception $e) { //var_dump( $e ); } $result = ob_get_contents(); ob_end_clean(); $response->end($result); }
public function testCase011() { $this->request->setRequestUri('/subdir/ap/1.2/name/value'); $this->request->setBaseUri('/subdir'); $route = new Yaf_Route_Rewrite("/subdir/:name/:version", array("action" => "version")); $this->router->addRoute("subdir", $route)->addRoute("ap", new Yaf_Route_Rewrite("/ap/:version/*", array("action" => 'ap')))->route($this->request); $this->assertEquals('ap', $this->router->getCurrentRoute()); $this->assertEquals('1.2', $this->request->getParam('version')); $this->assertEquals('ap', $this->request->getActionName()); $this->assertEquals(null, $this->request->getControllerName()); $this->assertEquals('value', $this->request->getParam('name')); }
public function onRequest($request, $response) { $response->status('200'); $ser = $request->server; $hea = $request->header; $hea['host'] = str_replace(':9501', '', $hea['host']); //如果端口号是80,就不用要此句代码 ob_start(); try { define('APPLICATION_PATH', dirname(dirname(__DIR__)) . "/application"); $this->application = new Yaf_Application(dirname(APPLICATION_PATH) . "/conf/application.ini"); $yaf_request = new Yaf_Request_Http($ser['request_uri']); $yaf_request->setBaseUri($hea['host']); $this->application->getDispatcher()->dispatch($yaf_request); } catch (Yaf_Exception $e) { //var_dump( $e ); } $result = ob_get_contents(); ob_end_clean(); $response->end($result); }
public function testCase06() { $this->request->setRequestUri("/prefix/controller/action/name/laruence/age/28"); $this->request->setBaseUri("/prefix/"); $route = new Yaf_Route_Static(); $this->assertTrue($route->route($this->request)); $this->assertEquals(null, $this->request->getModuleName(), 'The request param is set to module'); $this->assertEquals('controller', $this->request->getControllerName(), 'The request param is set to controller'); $this->assertEquals('action', $this->request->getActionName(), 'The request param is set to action'); $params = $this->request->getParams(); $this->assertEquals(array("name" => 'laruence', "age" => '28'), $params); }
/** * 获取传递的参数 * @param string $key key * @param bool|false $flag 是否返回原始数据 * @param array $unset 需要清除的参数 * @return array|string 返回获取到的值 */ public function getParam($key = '', $flag = false, $unset = array()) { $yafHttp = new Yaf_Request_Http(); if ($yafHttp->isGet()) { $array = $yafHttp->getQuery(); if ($key != '') { $array = $array[$key]; } } else { if ($key != '') { $array = $yafHttp->getPost($key); } else { $array = $yafHttp->getPost(); $arrayTem = $yafHttp->getQuery(); $array = array_merge($array, $arrayTem); } } if (count($unset) > 0) { foreach ($unset as $key) { unset($array[$key]); } } if ($flag) { return $array; } $tem = array(); if (count($array) > 0 && is_array($array)) { foreach ($array as $key => $val) { $tem[$key] = is_array($val) ? $val : addslashes(strip_tags($val)); } } else { $tem = !empty($array) ? addslashes(strip_tags($array)) : ''; } return $tem; }
public function testMapDelimiterInRequest() { $route = new Yaf_Route_Map(true, '_'); $this->request->setRequestUri('/user/list/_/foo/22'); $this->request->setBaseUri('/'); $return = $route->route($this->request); $this->assertTrue($return); $this->assertEquals(null, $this->request->getModuleName()); $this->assertEquals('user_list', $this->request->getControllerName()); $this->assertEquals(null, $this->request->getActionName()); $params = $this->request->getParams(); $this->assertEquals(array('foo' => '22'), $params); }
public function testSupervarManyParamInvalidModule() { //echo ini_get('yaf.action_prefer'); //echo getenv('action_prefer'); $_GET['page'] = '/FooN/Bar/Name/Value/Name1/Value1/Name2/Value2'; $route = new Yaf_Route_Supervar('page'); $return = $route->route($this->request); $this->assertTrue($return, 'The return of routing'); $this->assertEquals(null, $this->request->getModuleName(), 'The request param is set to module'); $this->assertEquals('FooN', $this->request->getControllerName(), 'The request param is set to controller'); $this->assertEquals('Bar', $this->request->getActionName(), 'The request param is set to action'); $params = $this->request->getParams(); $this->assertFalse(empty($params)); $this->assertEquals(array("Name" => 'Value', "Name1" => 'Value1', "Name2" => 'Value2'), $params); }
public function testSimpleInstanceConfig() { if (defined('YAF_MODE')) { $this->markTestSkipped('Yaf_Route_Simple does not allow to change the get'); return; } $_GET['module'] = 'Foo'; $_GET['controller'] = 'contr'; $_GET['action'] = 'action'; $config = new Yaf_Config_Ini("framework/Yaf/_files/route_simple.ini"); $this->router->addConfig($config->production->routes); $this->request->setRequestUri('/'); $this->request->setBaseUri('/'); $return = $this->router->route($this->request); $currentRouteName = $this->router->getCurrentRoute(); $this->assertEquals('route_name1', $currentRouteName); $currentRoute = $this->router->getRoute($currentRouteName); $this->assertInstanceOf('Yaf_Route_Simple', $currentRoute); $this->assertEquals('Foo', $this->request->getModuleName()); $this->assertEquals('contr', $this->request->getControllerName()); $this->assertEquals('action', $this->request->getActionName()); $params = $this->request->getParams(); $this->assertTrue(empty($params)); }
/** * Method onRequest * @desc http 请求部分 * @author WenJun <*****@*****.**> * @param swoole_http_request $request * @param swoole_http_response $response * @return void */ public function onRequest(swoole_http_request $request, swoole_http_response $response) { //清理环境 Yaf_Registry::flush(); Yaf_Dispatcher::destoryInstance(); //注册全局信息 $this->initRequestParam($request); Yaf_Registry::set('SWOOLE_HTTP_REQUEST', $request); Yaf_Registry::set('SWOOLE_HTTP_RESPONSE', $response); //执行 ob_start(); try { $requestObj = new Yaf_Request_Http($request->server['request_uri']); $configArr = Yaf_Application::app()->getConfig()->toArray(); if (!empty($configArr['application']['baseUri'])) { //set base_uri $requestObj->setBaseUri($configArr['application']['baseUri']); } $this->yafAppObj->bootstrap()->getDispatcher()->dispatch($requestObj); } catch (Yaf_Exception $e) { var_dump($e); } $result = ob_get_contents(); ob_end_clean(); $response->end($result); }