Knowledge Base

Getting Started

Advandz is a HMVC Framework

Advandz uses the Hierarchical Model-View-Controller approach, which allows great separation between logic and presentation. This is particularly good for projects in which designers are working with your template files, as the code these files contain will be minimized. Advandz also includes Knife, a simple and powerful templating engine that does not restrict you from using PHP code in your views.

Models, Controllers, Facades, Middleware and Views

Models

Models are PHP class files that store all the functions and logic of the application, Models are a great way to extend the framework functionality.

Controllers

Controllers are PHP class files that handle URI requests. Each controller and controller method (known as an action) represent a URI segment. For example, the "Foo" controller can be accessed at /foo/. This would automatically invoke the Foo::index() method. This method could explicitly be invoked using the /foo/index/ URI. Similarly, the "bar" method of Foo can be accessed at /foo/bar/.

Facades

Facades provide a "static" interface to classes that are available in the application. Advandz facades serve as "static proxies" to underlying classes in the application, providing the benefit of a terse, expressive syntax while maintaining more testability and flexibility than traditional static methods.

Middleware

Middleware provide a convenient mechanism for filtering HTTP requests entering your application. For example, you can make a middleware that verifies the user of your application is authenticated. If the user is not authenticated, the middleware will redirect the user to the login screen. However, if the user is authenticated, the middleware will allow the request to proceed further into the application controller.

Views

Each View is linked to a specific action. That is, each controller method has its own view. A view is a Knife Template (.knife file), which typically contain HTML and PHP. The view for /foo/index/ would be foo.pdt. The view for /foo/bar/ would be foo_bar.pdt. Views are located in the /app/views/default/ directory.

Controllers are initialized with two view objects. One for the action's view and another called "structure". The structure view (/app/views/default/structure.pdt) contains the content used in all views.

Also, you can use pure PHP code using the {{php}}{{/php}} tags.

Passing Variables from Controllers to Views

Passing variables to views from a controller is simple:

$my_var = [1,2,3];
$this->set("my_var", $my_var);

You can also set multiple variables all at once:

$my_var = [1,2,3];
$my_other_var = ["a","b","c"];
$this->set(compact("my_var", "my_other_var"));

To set variables in the structure view use:

$this->structure->set("my_var", $my_var);

Please rate this article to help us improve our Knowledge Base.

0 0