-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
root
committed
Feb 14, 2014
0 parents
commit ffc9e85
Showing
16 changed files
with
571 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
.DS_Store | ||
*/.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace TestProject\Frontend; | ||
|
||
use Phalcon\Loader, | ||
Phalcon\Mvc\View, | ||
Phalcon\Mvc\Url as UrlResolver, | ||
Phalcon\Mvc\ModuleDefinitionInterface, | ||
Phalcon\Exception, | ||
Phalcon\Session\Adapter\Cache as SessionAdapter; | ||
|
||
class Module implements ModuleDefinitionInterface | ||
{ | ||
public function registerAutoloaders() | ||
{ | ||
$loader = new Loader(); | ||
|
||
require CONFIG_PROJECT_PATH . 'config/loader.php'; | ||
|
||
$loader->registerNamespaces(array( | ||
'TestProject\Frontend\Plugins' => __DIR__ . '/plugins/' | ||
), true); | ||
|
||
$loader->register(); | ||
|
||
} | ||
|
||
public function registerServices($di) | ||
{ | ||
$di['config'] = function () { | ||
return new \Phalcon\Config(array( | ||
'application' => array( | ||
'controllersDir' => __DIR__ . '/../controllers/', | ||
'viewsDir' => __DIR__ . '/../views/' | ||
) | ||
)); | ||
}; | ||
|
||
$di['url'] = function () { | ||
$url = new UrlResolver(); | ||
$url->setBaseUri('/'); | ||
$url->setStaticBaseUri('/'); | ||
return $url; | ||
}; | ||
|
||
|
||
$di['view'] = function () { | ||
$view = new View(); | ||
$view->setViewsDir(__DIR__ . '/views/'); | ||
return $view; | ||
}; | ||
|
||
$di['dispatcher'] = function () use ($di) { | ||
|
||
$eventsManager = $di->getShared('eventsManager'); | ||
|
||
$test = new \TestProject\Frontend\Plugins\Test(); | ||
|
||
$eventsManager->attach('dispatch', $test); | ||
|
||
$dispatcher = new \Phalcon\Mvc\Dispatcher(); | ||
$dispatcher->setEventsManager($eventsManager); | ||
|
||
return $dispatcher; | ||
}; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace TestProject\Frontend\Controllers; | ||
use Phalcon\Mvc\Controller, | ||
Phalcon\Tag as Tag; | ||
/** | ||
* Class ErrorController | ||
* @package TestProject\Frontend\Controllers | ||
* | ||
* @RoutePrefix("/error") | ||
* | ||
*/ | ||
class ErrorController extends Controller | ||
{ | ||
|
||
public function initialize() | ||
{ | ||
|
||
} | ||
/** | ||
* @Get("/404", name="pageNotFound") | ||
* | ||
* Example for setting other status codes than 200. | ||
* | ||
*/ | ||
public function pageNotFoundAction() | ||
{ | ||
$this->response->setStatusCode(404, "Page not found"); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace TestProject\Frontend\Controllers; | ||
|
||
use Phalcon\Mvc\Controller, | ||
Phalcon\Tag as Tag; | ||
|
||
/** | ||
* Class IndexController | ||
* @package TestProject\Frontend\Controllers | ||
* | ||
*/ | ||
class IndexController extends Controller | ||
{ | ||
/** | ||
* @Get("/") | ||
*/ | ||
public function indexAction() | ||
{ | ||
|
||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
namespace TestProject\Frontend\Controllers; | ||
use Phalcon\Mvc\Controller, | ||
Phalcon\Tag as Tag; | ||
|
||
/** | ||
* Class MyAweseomeTestController | ||
* @package TestProject\Frontend\Controllers | ||
* | ||
* @RoutePrefix("/awesome-test") | ||
* | ||
*/ | ||
class MyAwesomeTestController extends Controller | ||
{ | ||
/** | ||
* @Get("/super-action", name="logout") | ||
* | ||
*/ | ||
public function mySuperTestAction() | ||
{ | ||
$this->view->setVar('date', date('Y-m-d')); | ||
} | ||
|
||
/** | ||
* @Get("/forward-test") | ||
*/ | ||
public function forwardTestAction() | ||
{ | ||
$this->dispatcher->forward(array( | ||
'controller' => 'myAwesomeTest', | ||
'action' => 'mySuperTest' | ||
)); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace TestProject\Frontend\Plugins; | ||
|
||
use Phalcon\Events\Event, | ||
Phalcon\Mvc\User\Plugin, | ||
Phalcon\Mvc\Dispatcher, | ||
Phalcon\Acl, | ||
Phalcon; | ||
|
||
/** | ||
* Class Test | ||
* @package TestProject\Frontend\Plugins | ||
* | ||
*/ | ||
class Test extends Plugin | ||
{ | ||
public function beforeDispatch(Event $event, Dispatcher $dispatcher) | ||
{ | ||
$controller = $dispatcher->getControllerName(); | ||
$action = $dispatcher->getActionName(); | ||
|
||
header('X-Controller: '.$controller); | ||
header('X-Action: '.$action); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h2>This is the pageNotFound page!</h2> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
use Phalcon\Tag as Tag; | ||
|
||
?> | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<?php echo Tag::getTitle() ?> | ||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> | ||
<meta http-equiv="pragma" content="no-cache"/> | ||
<meta http-equiv="cache-control" content="no-cache"/> | ||
<meta http-equiv="expires" content="0"/> | ||
<meta name="robots" content="noindex, nofollow"/> | ||
</head> | ||
|
||
<body> | ||
|
||
<h1>TestProject</h1> | ||
<hr/> | ||
<?php echo $this->getContent(); ?> | ||
<hr /> | ||
<?php echo Phalcon\Version::get(); ?> | ||
|
||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<p><strong>Results in Phalcon 1.2.6:</strong></p> | ||
<p>This view is located at '/apps/frontend/views/index/index.phtml'</p> | ||
<p>Try this link: <a href="/awesome-test/super-action">/awesome-test/super-action</a>, it will call action 'mySuperTestAction' in 'MyAwesomeTestController' and load the view '/apps/frontend/views/myAwesomeTest/mySuperTest.phtml'.</p> | ||
<p>Then try this link: <a href="/awesome-test/forward-test">/awesome-test/forward-test</a>, it will forward to action 'mySuperTestAction' in 'MyAwesomeTestController' and try to load the view '/apps/frontend/views/myAwesomeTest/mySuperTest.phtml' which is <s>inconsistent but</s> <em>finnally consistent :) and</em> matches the behaviour below.</p> | ||
<p>But if you try this link: <a href="/i-do-not-exist">/i-do-not-exist</a>, it will fall back to action 'pageNotFoundAction' in 'ErrorController' and load the view '/apps/frontend/views/error/pageNotFound.phtml'.</p> | ||
<p>You can watch the headers 'X-Action' and 'X-Controller' to see what's the output of the 'beforeDispatch' event.</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<h2>This is the view for mySuperTestAction!</h2> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
$loader->registerNamespaces(array( | ||
'Nischenspringer' => CONFIG_PROJECT_PATH . 'library/Nischenspringer/', | ||
'TestProject\Frontend\Controllers' => CONFIG_PROJECT_PATH . 'apps/frontend/controllers/' | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
$application->registerModules(array( | ||
'frontend' => array( | ||
'className' => 'TestProject\Frontend\Module', | ||
'path' => CONFIG_PROJECT_PATH . 'apps/frontend/Module.php' | ||
) | ||
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
|
||
use Phalcon\Mvc\Router, | ||
Phalcon\DI\FactoryDefault; | ||
|
||
|
||
$di['router'] = function () { | ||
|
||
$router = new \Nischenspringer\Mvc\Router\Annotations(false); | ||
|
||
$router->setUriSource(\Phalcon\Mvc\Router::URI_SOURCE_SERVER_REQUEST_URI); | ||
$router->removeExtraSlashes(true); | ||
|
||
$router->notFound( | ||
array( | ||
'namespace' => 'TestProject\Frontend\Controllers', | ||
'module' => 'frontend', | ||
'controller' => 'error', | ||
'action' => 'pageNotFound' | ||
) | ||
); | ||
|
||
$router->addModuleResource('frontend', 'TestProject\Frontend\Controllers\Index'); | ||
$router->addModuleResource('frontend', 'TestProject\Frontend\Controllers\MyAwesomeTest'); | ||
$router->addModuleResource('frontend', 'TestProject\Frontend\Controllers\Error'); | ||
|
||
return $router; | ||
}; | ||
|
||
$di['annotations'] = function () { | ||
return new \Phalcon\Annotations\Adapter\Memory(); | ||
}; |
Oops, something went wrong.