This is: First page based controller (MVC)
This tutorial is built in parts, it is imperative to start from the begining, so it will be easier to understand the processes on this framework, since every part rely on the previous part. This demonstration is based on the files designated on "Files in use" in the middle of this page. to complete our knowledge it is recommended to look for the documents on limbercode.com
We can edit the "view" file (file number 1) and the content of this page will be changed.
Controllers have actions that's operates and run under it's name. action function name does not have to
start with the word "action", we simply choose the name we want to use as a function (file number 2). in
this page we are using public function index() {
as a controller since we don't want anything
other then the controller name in the url.
If we want to make a function that won't be an action, we simply make it private (file number 2), such as
private function whoAreYou() {
. private functions can't be called as action. we can only use it
inside the controller, but can be called from other controllers as well with the help of core function - we
won't show in this demo.
With the help of the controller (file number 2) we can insert variables to the content of this page - for
passing variables like the "title", we used $this->view->title
in the controller. to put it in
the view file (file number 1) we used $this->title
for the same variable.
To get data from the "model" into the "controller" and then passing it to the "view", we have to fetch it
first. here in this demonstration we will use a builtin function and not "mysql" as common framework will
do, but
for sure it is possible here too. what we want to do in this demo is to get/show the first line of this page
text from the model and by the controller. the model file (file number 3) can fetch the data for us - function
getData()
will do just so with the help of $this->loadData($name)
we are getting the
data from the data file (file number 4) by giving the function the parameter of the file location that holds
the
data (file number 4) "demonstrationData".DS."main"
. after we have the data needed, we can
assign
the data to the view for display: $this->view->firstLine = $data->firstLine
.
In the controller we can also assign css/js files, we can do that by using the function init()
that
every controller should have. $this->addCssIncludes("css/demo.css")
will insert the css file
(file
number 5) into the html head of this page according to site configuration.
Notice the url routing at our browser http address. if we want to inflict the first string after the domain and after the "/" sign, we will use index.php at the directory we want to use as string on the url. in this example we use the firstPageBasedController directory.
Files in use: (not including template files)
1 - View (a must): architecture/application/views/firstPageBasedController/index.php
2 - Controller (a must): architecture/application/controllers/firstPageBasedControllerController.php
3 - Model (optional): architecture/application/models/firstPageBasedControllerModel.php
4 - Model data (db like) (optional): source/data/demonstrationData/main.php
5 - Css (optional): public/css/demo.css
Navigate:
homePage - Home page
firstPageBasedView - First page based "view" firstPageBasedViewMu - For multi language support
pageNum2BasedView - Page number 2 based "view" pageNum2BasedViewMu - For multi language support
firstPageBasedController - First page based "controller" firstPageBasedControllerMu - For multi language support
pageNum2BasedController - Page number 2 based "controller" pageNum2BasedControllerMu - For multi language support