1实现mvc
出现helloword,成功
2.controller重定向
$get = $this->getRequest()->getQuery("get", "default value"); //2. fetch model
$model = new SampleModel();
$this->forward("login");
//3. assign
$this->getView()->assign("content", $model->selectSample());
$this->getView()->assign("name", $name);
$this->forward("login");
会出现两个index模版和login模版同时加载的情况。
$this->redirect("index/login");
public function indexAction($name = "Stranger") {
//1. fetch query
$get = $this->getRequest()->getQuery("get", "default value"); //2. fetch model
$model = new SampleModel();
$this->redirect("index/login");
//3. assign
$this->getView()->assign("content", $model->selectSample());
$this->getView()->assign("name", $name); //4. render by Yaf, 如果这里返回FALSE, Yaf将不会调用自动视图引擎Render模板
return TRUE;
}
会重定向到http://localhost/yafdemo/index/login成功跳转
3.model模式
在使用自己编写的数据库操作类的时候,没遇到什么问题。
public function _initDatabase()
{
$db_config['hostname'] = $this->arrConfig->db->hostname;
$db_config['username'] = $this->arrConfig->db->username;
$db_config['password'] = $this->arrConfig->db->password;
$db_config['database'] = $this->arrConfig->db->database;
// $db_config['log'] = $this->arrConfig->db->log;
header("Content-type: text/html; charset=utf-8");
Yaf_Registry::set('db', new Db($db_config));
}
4.路由测试
$router = Yaf_Dispatcher::getInstance()->getRouter();
// $route = new Yaf_Route_Rewrite('product/:ident',array('module'=>'User','controller' => 'Index','action' => 'test'));
//使用路由器装载路由协议
//$router->addRoute('product', $route);
$route = new Yaf_Route_Rewrite('cc',array('controller' => 'Index','action' => 'index'));
//使用路由器装载路由协议
$router->addRoute('cc', $route);
路由还有可以在aplication.ini配置的模式,大同小异。
5.引用css,js测试
发现一个问题,就是localhost/public/js/public.js这样的路径居然不可以,但是../public/js/public.js却可以,很神奇。
<html>
<link rel="stylesheet" href="<?=BASICURL?>public/css/common.css" type="text/css">
<script type="text/javascript" src="<?=BASICURL?>public/js/public.js"></script>
<body> <form action="../index/login" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="hidden" value="1" name="submit">
<input type="submit">
</form>
<div>1</div> </body>
</html>
6、表单测试
表单测试没有问题。
<html>
<link rel="stylesheet" href="<?=BASICURL?>public/css/common.css" type="text/css">
<script type="text/javascript" src="<?=BASICURL?>public/js/public.js"></script>
<body> <form action="../index/login" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="hidden" value="1" name="submit">
<input type="submit">
</form>
<div>1</div> </body>
</html>
具体下载地址https://github.com/Wen1750686723/yafdemo
如果想看yaf在wamp上如何安装,请看上篇。