diff --git a/README.md b/README.md index eb1a6b1..7219c9d 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Routes match one to one to controllers and actions. In this url: http://example.com/watch/video/id - + `watch` is the controller, `video` is the action and `id` is a parameter for the action (you can have multiple parameters like `http://example.com/watch/video/id/param2/param3`). ## Controllers @@ -58,15 +58,15 @@ For the previous examples, we would have a `/controllers/watch.php` file like th // some php code } } - + or like this: - + Class Watch extends Controller { static function video($id, $param2, $param3) { // some php code } } - + The route, file name and class name must be the same (in this case `watch`). ## Views @@ -75,21 +75,21 @@ Views are just php files with embedded html. You could have a view located in `/views/hello_view.php` with something like this: -

- +

Hello World

+ And you would use it from a controller like this: Class Watch extends Controller { static function video($id) { - echo Watch::view('hello_view'); + echo Watch::view('hello_view'); // echo Controller::view('hello_view') you can also use the parent controller class } } - + You can send variables to the view, so a view like this:

- + Would be called from the controller like this: Class Watch extends Controller { @@ -97,7 +97,7 @@ Would be called from the controller like this: echo Watch::view('hello_view', array('$video_id' => $id)); } } - + ## Models Models use PDO with parametrized sql (parameters are optional). Only one function is available, named 'exec'. @@ -112,14 +112,14 @@ A model in `/models/Watch_Model.php` would look like this: return $this->exec('SELECT * FROM videos WHERE id = :video_id', array(':video_id' => $id)); } } - + And would be called from a controller like this: Class Watch extends Controller { static function video($id) { $watch_model = Watch::model('Watch_Model'); // you can also use Controller instead of Watch $video = $watch_model->get_video($id); - echo Watch::view('hello_view', array('video' => $video)); + echo Watch::view('hello_view', array('video' => $video)); } } @@ -140,4 +140,4 @@ Redirects every request to index.php (except for files, like your css or js) and Acknowledgements ---------------- -This is heavily inspired by [PIP](https://github.com/gilbitron/PIP). +This is heavily inspired by [CodeIgniter](https://github.com/bcit-ci/CodeIgniter) and [PIP](https://github.com/gilbitron/PIP). diff --git a/config.php b/config.php index 9d73d15..f8a29cf 100644 --- a/config.php +++ b/config.php @@ -1,7 +1,7 @@ 'Hail Hyrdra!', + 'link' => '/hello/say/hello', + 'link_text' => 'Say Hello')); + } + + static function say($message='') { + echo Hello::view('hello_view', + array('message' => $message, + 'link' => '/hello', + 'link_text' => 'Go Back')); + } +} diff --git a/views/404_view.php b/views/404_view.php new file mode 100644 index 0000000..7536ddd --- /dev/null +++ b/views/404_view.php @@ -0,0 +1,2 @@ + +

404

\ No newline at end of file diff --git a/views/hello_view.php b/views/hello_view.php new file mode 100644 index 0000000..8f88baf --- /dev/null +++ b/views/hello_view.php @@ -0,0 +1,3 @@ + +

+ \ No newline at end of file