Recommend this page to a friend! |
Classes of Alexey Dodonov | mezon PHP Application | README.md | Download |
|
DownloadBase application classIntroAll your applications will be derived from this class or will be using classes wich are siblings of this Application class. FunctionalityThis class provieds:
Loading routes from config fileWith time your application will grow and number of routes will increase. So we have provided convinient way to store all routes in a standalone config file. So it is not necessary to initialize all routes in an Application (or any derived class) object's constructor. Let's find out how you can use it. First of all create config file ./conf/routes.php in your projects directory. It must look like this:
Note that the 'method' field is not set then it will be defaulted to GET. You can also specify your own config file. Then just call Application::loadRoutesFromConfig()
Common application classIntroThis class provides simple aplication routine. Using this class you can create veri simple applications with the basic template wich looks like black text on white background. It can be simply used for prototyping. Extended routes processingIn Application class routes may return only strings. But CommonApplication class allows you to return arrays of string wich will be placed in the template placeholders. Simple example:
Here route's handler generates two parts of the page /simple-page/ - 'title' and 'main'. These two part will be inserted into {title} and {main} placeholders respectively. More complex example:
Here we pass instance of the class View (or any class derived from View) to the application page compilator. It will call View::render method wich must return compiled html content. Routes configYou can also keep al routes in configs. You can use json configs:
This data must be stored in the './conf/' dir of your project. Or load configs explicitly as shown below (using method loadRoutesFromConfig). And we also need these methods in the application class.
Note that you can load multiple configs with one call of the method loadRoutesFromConfigs
Or the same:
|