Skip to content

Commit c563779

Browse files
committed
todo done!
1 parent c78979a commit c563779

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1083
-571
lines changed

.idea/workspace.xml

+292-287
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
"# mymvc"
1+
##四脚猫轻量级框架sijiaomao-mvc
2+
3+
- 路由规则简单
4+
- orm简单 <https://packagist.org/packages/lox/pheasant>
5+
- 模版引擎<https://latte.nette.org/>
6+
- 配置文件简单解析
7+
- migration简单 Pheasant
8+
- 初始化简单,自动化生成control、model、view,然后填空
9+
- 分页 <https://github.com/jasongrimes/php-paginator>
10+
11+
12+
## 基本使用
13+
- 安装
14+
- 解决
15+

app/controllers/BaseController.php

+15-11
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88

99
namespace app\controllers;
1010

11+
use Pheasant;
12+
use Latte\Engine;
1113

1214
class BaseController
1315
{
1416
private $latte;
1517

1618
public function __construct()
1719
{
18-
// $this->middleware('auth');
20+
$this->initDb();
21+
$this->initTpl();
1922
}
2023

2124
public function initDb()
@@ -25,25 +28,26 @@ public function initDb()
2528

2629
public function initTpl()
2730
{
28-
$this->latte = new \Latte\Engine();
31+
$this->latte = new Engine();
2932
$this->latte->setTempDirectory(__DIR__ . '/../storage/views');
33+
$set = new \Latte\Macros\MacroSet($this->latte->getCompiler());
34+
$set->addMacro('url', function ($node, $writer) {
35+
return $writer->write('echo "' . SITE_URL . '%node.args' . '"');
36+
});
3037
}
3138

3239
public function render($name, array $params = [], $block = NULL)
3340
{
3441
$params['sitename'] = 'sijiaomao mvc framework';
35-
$this->latte->render($name, $params, $block);
42+
$tplFile = __DIR__ . '/../views/' . $name . '.latte';
43+
$this->latte->render($tplFile, $params, $block);
3644
}
3745

38-
public static function __callStatic($method, $args)
46+
public function redirect($name)
3947
{
40-
$instance = static::getFacadeRoot();
41-
42-
if (! $instance) {
43-
throw new RuntimeException('A facade root has not been set.');
44-
}
45-
46-
return $instance->$method(...$args);
48+
header('Location:' . SITE_URL . '/' . $name);
49+
exit;
4750
}
4851

52+
4953
}

app/controllers/HomeController.php

+17-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace app\controllers;
44

5-
use app\controllers\BaseController;
65
use app\models\Post;
76
use app\models\Author;
7+
use app\models\ToDo;
88

99

1010
class HomeController extends BaseController
@@ -16,35 +16,41 @@ class HomeController extends BaseController
1616
*/
1717
public function __construct()
1818
{
19+
//如果要自定义构造函数,那么必须去显示调用父类的构造函数
20+
parent::__construct();
1921
// $this->middleware('auth');
2022
}
2123

2224

23-
2425
public function index($arg1)
2526
{
26-
echo '我故意的 home.index ',$arg1 ;
27+
echo '我故意的 home.index ', $arg1;
2728
//print_r(func_get_args());
28-
// throw new \Exception("我故意的", 1);
29+
// throw new \Exception("我故意的", 1);
2930
//return view('home');
3031
//$this->view->render();
3132
//$this->view('home',[]);
32-
// return view('home')->with('articles', \App\Article::all());
33+
// return view('home')->with('articles', \App\Article::all());
3334
//return view('home')->withArticles(\App\Article::all());
3435
}
3536

3637
/*
3738
* 按照模型的字段设定,创建数据库表
3839
* */
39-
public function migrate(){
40+
public function migrate()
41+
{
4042
$migrator = new \Pheasant\Migrate\Migrator();
41-
$migrator->initialize( Post::schema(),'post');
42-
$migrator->initialize( Author::schema(),'author');
43-
echo 'migrate post done! <br>';
43+
$migrator->initialize(ToDo::schema(), 'todo');
4444
echo 'migrate author done! <br>';
45+
// $migrator->initialize(Post::schema(), 'post');
46+
// $migrator->initialize(Author::schema(), 'author');
47+
// echo 'migrate post done! <br>';
48+
// echo 'migrate author done! <br>';
4549
}
4650

47-
public function show(){
48-
echo 'Home@show';
51+
public function show()
52+
{
53+
$articles = Post::all()->includes(['Author']);
54+
$this->render('article/show', ['articles' => $articles]);
4955
}
5056
}

app/controllers/ToDoController.php

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Cral
5+
* Date: 2016/11/16 0016
6+
* Time: 下午 4:09
7+
*/
8+
9+
namespace app\controllers;
10+
11+
use app\models\ToDo;
12+
13+
class ToDoController extends BaseController
14+
{
15+
16+
17+
/**
18+
* Display a listing of the resource.
19+
*
20+
*/
21+
public function index()
22+
{
23+
$todos = ToDo::all();
24+
return $this->render('todo/index', ['todos' => $todos]);
25+
}
26+
27+
/**
28+
* Show the form for creating a new resource.
29+
*
30+
*/
31+
public function create()
32+
{
33+
return $this->redirect('todo/index');
34+
}
35+
36+
/**
37+
* Store a newly created resource in storage.
38+
*
39+
*/
40+
public function store()
41+
{
42+
$toDo = new ToDo();
43+
$toDo->title = $_POST['title'];
44+
$toDo->status = false;
45+
$toDo->save();
46+
return $this->redirect('todo/index');
47+
}
48+
49+
/**
50+
* Display the specified resource.
51+
*
52+
* @param int $id
53+
*/
54+
public function show($id)
55+
{
56+
//
57+
}
58+
59+
/**
60+
* Show the form for editing the specified resource.
61+
*
62+
* @param int $id
63+
*/
64+
public function edit($id)
65+
{
66+
$toDo = ToDo::byId($id);
67+
$toDo->status = true;
68+
$toDo->save();
69+
return $this->redirect('todo/index');
70+
}
71+
72+
/**
73+
* Update the specified resource in storage.
74+
*
75+
* @param int $id
76+
*/
77+
public function update(Request $request, $id)
78+
{
79+
//
80+
}
81+
82+
/**
83+
* Remove the specified resource from storage.
84+
*
85+
* @param int $id
86+
*/
87+
public function destroy($id)
88+
{
89+
$toDo = ToDo::byId($id);
90+
$toDo->delete($id);
91+
return $this->redirect('todo/index');
92+
}
93+
94+
}

app/models/Author.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
namespace app\models;
99

10-
use Pheasant\Types;
10+
use \Pheasant\Types;
1111

1212
class Author extends BaseModel
1313
{

app/models/Post.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace app\models;
1111

12-
use Pheasant\Types;
12+
use \Pheasant\Types;
1313

1414
class Post extends BaseModel
1515
{
@@ -19,7 +19,7 @@ public function properties()
1919
'postid' => new Types\SequenceType(),
2020
'title' => new Types\StringType(255, 'required'),
2121
'subtitle' => new Types\StringType(255),
22-
'status' => new Types\EnumType(array('closed','open')),
22+
'status' => new Types\SetType(array('closed','open')),
2323
'authorid' => new Types\IntegerType(11),
2424
);
2525
}

app/models/ToDo.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace app\models;
4+
5+
use \Pheasant\Types;
6+
7+
class ToDo extends BaseModel {
8+
9+
public function properties()
10+
{
11+
return array(
12+
'id' => new Types\SequenceType(),
13+
'title' => new Types\StringType(255, 'required'),
14+
'status' => new Types\BooleanType(),
15+
);
16+
}
17+
18+
19+
20+
}

app/readme.md

-21
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
// source: D:\demos\myMVC\app\controllers/../views/article/show.latte
3+
4+
use Latte\Runtime as LR;
5+
6+
class Templateea79440150 extends Latte\Runtime\Template
7+
{
8+
9+
function main()
10+
{
11+
extract($this->params);
12+
if ($articles) {
13+
?><ul>
14+
<?php
15+
$iterations = 0;
16+
foreach ($iterator = $this->global->its[] = new LR\CachingIterator($articles) as $article) {
17+
?>
18+
19+
<li id="article-<?php echo LR\Filters::escapeHtmlAttr($iterator->counter) /* line 3 */ ?>"><?php echo LR\Filters::escapeHtmlText($article['title']) /* line 3 */ ?> <?php
20+
echo LR\Filters::escapeHtmlText(call_user_func($this->filters->upper, $article['Author']['fullname'])) /* line 3 */ ?> </li>
21+
<?php
22+
$iterations++;
23+
}
24+
array_pop($this->global->its);
25+
$iterator = end($this->global->its);
26+
?></ul><?php
27+
}
28+
return get_defined_vars();
29+
}
30+
31+
32+
function prepare()
33+
{
34+
extract($this->params);
35+
if (isset($this->params['article'])) trigger_error('Variable $article overwritten in foreach on line 2');
36+
37+
}
38+
39+
}

0 commit comments

Comments
 (0)