front-controller

PHP Front Controller with MVC

流过昼夜 提交于 2019-12-06 07:17:32
I am trying to delve into MVC with Front Controller Design. I want to invoke my entire application by using one line, for example in index.php: require_once(myclass.php); $output = new myClass(); I would love to get rid of the require_once line, but I don't see how I could load my class without including it? Anyway my main question would be how to load my various controllers and models and views etc using a one front end class. So far I have come up with: class myClass { private $name; public $root = $_SERVER['DOCUMENT_ROOT']; private $route = array("Controller" => "", "Model" => "", "View" =>

Front controller pattern - is router a front controller?

…衆ロ難τιáo~ 提交于 2019-12-05 17:12:11
I'm trying to understand how a Front Controller should look like. From Wikipedia, The Front Controller pattern is a software design pattern listed in several pattern catalogs. The pattern relates to the design of web applications. It "provides a centralized entry point for handling requests." So, is the code below that handles routes in Slim a front controller? $app = new \Slim\Slim(); $app->get('/books/:id', function ($id) use ($app) { // Get all books or one book. $bookModel = new ... $bookController = new ... $app->render('myTemplate.php', array('id' => $id, ...)); }); $app->run(); provides

Where should autloader go in MVC?

冷暖自知 提交于 2019-12-05 01:25:20
问题 I'm trying to build a simple MVC framework to better understand certain concepts. The first thing that I thought would be important to address is a front controller that handles all of the requests for my applications. Once I started to think about it, I wasn't sure of the best way to load the classes that my application would be using. My current thought process is that my autoloader should be located in the front controller since every request utilizes it. Where do most frameworks typically

Routing URL Path with PHP and Apache

给你一囗甜甜゛ 提交于 2019-12-04 16:38:38
I am trying to create a nice url structure for my site. My router class will only work if the url is in the style of ?something=value. How do I get it so it will work like: /something/value In my .htaccess I have: Options FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule !\.(js|txt|gif|jpg|png)$ index.php?$1 [L,QSA] And in my router class I'm making: class init { function __construct() { $URL = substr($_SERVER['REQUEST_URI'], 19) ; $URLElements = explode('/', $URL) ; // Adjust if needed. $class = $URLElements[0] ; $method =

get current controller

无人久伴 提交于 2019-12-04 13:30:10
问题 in a function I want to reach current controller: $front = Zend_Controller_Front::getInstance(); this only gives a handler but not current controller. I changed the code from function to inside of controller. and asked their origins both the handler I got from getInstance and this var_dump(get_class($front), get_class($this)); I get: string 'Zend_Controller_Front' (length=21) string 'IndexController' (length=15) How can I reach real initiated front controller? I cant pass as a parameter,

Zend_Framework- Where to Place $_GET and $_POST (HTTP Request) handling?

杀马特。学长 韩版系。学妹 提交于 2019-12-04 12:53:36
I recently read this post which led to a series of other posts that all seem to suggest the same idea: Models do everything, the View should be able to communicate directly with the model and vice versa all while the Controller stays out of the way. However, all of the examples shown are fairly simplistic and none really show an example of how anyone has tried to implement full handling of of a request / response cycle, which got me to wondering "should the model be responsible for handling the request (ie $_GET, $_POST, etc) itself?" and "should the controller only operate as a pass-through

Getting View Object from within a Zend Controller plugin

自作多情 提交于 2019-12-01 08:15:11
In my controller, I have a postDispatch to consolidate my FlashMessenger messages: public function postDispatch() { $messages = $this->_helper->getHelper ( 'FlashMessenger' ) ->getMessages (); if ( $this->_helper->getHelper ( 'FlashMessenger' ) ->hasCurrentMessages () ) { $messages = array_merge ( $messages, $this->_helper->getHelper ( 'FlashMessenger' ) ->getCurrentMessages () ); $this->_helper->getHelper ( 'FlashMessenger' ) ->clearCurrentMessages (); } $this->view->alert = $messages; } I want to make this into a Controller plugin. UPDATE: I realized why I need this - I want to pass my flash

Getting View Object from within a Zend Controller plugin

眉间皱痕 提交于 2019-12-01 07:07:46
问题 In my controller, I have a postDispatch to consolidate my FlashMessenger messages: public function postDispatch() { $messages = $this->_helper->getHelper ( 'FlashMessenger' ) ->getMessages (); if ( $this->_helper->getHelper ( 'FlashMessenger' ) ->hasCurrentMessages () ) { $messages = array_merge ( $messages, $this->_helper->getHelper ( 'FlashMessenger' ) ->getCurrentMessages () ); $this->_helper->getHelper ( 'FlashMessenger' ) ->clearCurrentMessages (); } $this->view->alert = $messages; } I

How to create user-friendly and seo-friendly urls in jsf?

依然范特西╮ 提交于 2019-11-29 04:20:09
For example, I have class Article with methods getTitle () and getContent () . I also have ArticlesService with method getAllArticles () . How to create a list of links with meaningful names (formed with #{article.title} )? Like: http://mysiteaddress.com/article/first-article-title http://mysiteaddress.com/article/how-to-make-links-in-jsf ..or something similar. I can create links with all necessary functionality with <h:commandLink> , but I don't know how to make nice 'href' for it: it always has href '#'. I can create nice links with <h:outputLink> but I don't know how to add necessary

How to redirect all requests to a file, except images using Apache?

拟墨画扇 提交于 2019-11-29 01:16:36
I have an .htaccess file with the following contents: Options +FollowSymLinks +ExecCGI <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^(.*)$ entryPoint.php [QSA] </IfModule> With this, I want all requests to be redirected to the file entryPoint.php so that it can examine them: If there is no extension, is must be a module If there's a .php, it's a hacking If it's a .png, then it's a "safe" call. In case of images, I used to output headers, and file_get_contents() their content. I figured out it's a bit slower than leaving a direct read. My question is: How to prevent this .htaccess from