Controllers

The Controller is the part of a module that handles a request. Controllers are responsible for receiving a request, and returning a response. In Alloy, this literally translates to each web-accessible controller method receiving a Request object as the first parameter, and using a return statement to respond with a string, view, or other response type.

Alloy does not automatically load or attach anything onto your controller, like views or models. The dispatch cycle in Alloy is extremely lightweight, and does little more than instantiate your controller class and call the requested method. This allows Alloy to dispatch HMVC nested sub-requests just like normal code libraries, and at near-zero cost.

Alloy requires you to be a little more explicit about what you want to do within a controller action than most other php frameworks. The rendered content is explicitly set by you issuing a return statement rather than the dispatch loop automatically (implicitly) loading a view template of the same name as the action called, assuming it's going to be there. This is intentional, and allows you greater flexibility over what content is rendered, when, and how.

Method Conventions - RESTful by Default

Web-Accessible controller methods are appended with either "Action" or "Method", depending on the request context. If the action "view" is determined from a matched URL route with a HTTP GET request, the method "viewAction" will be called. Conversely, if the same route is matched with a HTTP DELETE request, the method "deleteMethod" will be called instead. This design prevents incidental deletions and conforms to REST principles because a user will never be able to delete a resource with a simple GET request if you follow this convention. 

Example URLs and controllers based on default URL routes distributed with Alloy. Routes are easy to change and customize if you do not want or desire this behavior.

GET /events/1743
Controller: app/Module/Events/Controller.php
Method: viewAction

GET /users/new
Controller: app/Module/Users/Controller.php
Method: newAction

POST /users/new
Controller: app/Module/Users/Controller.php
Method: postMethod

DELETE /users/new
Controller: app/Module/Users/Controller.php
Method: deleteMethod

Alloy was designed with REST in mind from the beginning. The "{name}Method" controller methods are special because they can only be accessed by using the corresponding HTTP method. This semantic difference enables true RESTful behavior, because it separates processing actions from requesting ones, while still allowing you to use the same URL.

All web-accessible controller methods accept exactly one parameter: an \Alloy\Request object. Any named parameters captured or set by the matched route will be set on the request object in the dispatch cycle so they can be easily accessed anywhere in your application.

The "Hello World" Example

Also known as the simplest example possible to make the phrase "Hello World" appear on the screen within the framework's rules and boundaries.


            
namespace Module\Home; use Alloy; class Controller extends Alloy\Module\ControllerAbstract { public function indexAction(Alloy\Request $request) { return "Hello World!"; } }

          
Note the namespace declaration at the top - this follows the PSR-0 namespace autoload spec and will mirror the module's folder path. So with \Module\Home, this file would be expected to be at: app/Module/Home/Controller.php

Transaksi Cepat dan Mudah di Slot 5k dengan Metode Pembayaran Beragam

Dengan deposit minimal hanya 5k, transaksi di Slot 5k bisa dilakukan dengan cepat dan mudah. Banyak situs menawarkan berbagai metode pembayaran seperti e-wallet dan bank transfer, serta pembayaran instan menggunakan QRIS, yang memungkinkan pemain untuk melakukan transaksi dalam hitungan detik.

Selain menawarkan gameplay yang menarik, Mahjong Ways juga dikenal karena volatilitasnya yang seimbang, memberikan kesempatan yang baik bagi pemain untuk memenangkan hadiah besar tanpa terlalu mengandalkan keberuntungan semata. Keberadaan fitur-fitur inovatif dalam permainan ini, seperti putaran gratis yang dapat diperoleh dengan simbol tertentu, semakin meningkatkan daya tarik Mahjong Ways di kalangan para pemain slot. Dalam setiap putaran, pemain merasa tertantang untuk mencari kombinasi simbol yang tepat yang dapat menghasilkan kemenangan. Mahjong Ways terus menjadi salah satu permainan slot yang paling dicari, dengan banyak pemain yang kembali lagi untuk merasakan sensasi permainan ini.

Dalam dunia perjudian online, Slot Toto menjadi salah satu permainan yang paling diminati. Dengan kombinasi fitur menarik dan jackpot progresif, permainan ini menawarkan pengalaman bermain yang seru dan menguntungkan. Banyak pemain yang berhasil mendapatkan kemenangan besar hanya dengan modal kecil di slot toto.

Slot 777 Pengalaman Bermain Seru dan Penuh Tantangan

Slot 777 menyediakan pengalaman bermain yang seru dan penuh tantangan. Dengan berbagai pilihan permainan dan fitur menarik, platform ini memberikan peluang menang yang lebih besar bagi para pemain yang ingin meraih kemenangan besar.

Pilihan Favorit untuk Menang Besar dengan Pasaran Lengkap

Toto Togel merupakan pilihan favorit para pemain yang mencari kesempatan besar untuk menang. Dengan pasaran yang lengkap dan selalu diperbarui, situs ini memberikan peluang tinggi bagi pemain untuk memperoleh angka yang tepat dan memenangkan hadiah besar.

Keluaran Macau memberikan informasi yang sangat dibutuhkan oleh para pemain togel yang sedang mencari angka jitu. Setiap angka yang keluar di Keluaran Macau selalu menjadi topik pembicaraan hangat di kalangan penggemar togel.

Related Links