Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Feb 14, 2014
0 parents commit ffc9e85
Show file tree
Hide file tree
Showing 16 changed files with 571 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
.DS_Store
*/.DS_Store
69 changes: 69 additions & 0 deletions apps/frontend/Module.php
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;
};

}

}
32 changes: 32 additions & 0 deletions apps/frontend/controllers/ErrorController.php
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");
}

}

24 changes: 24 additions & 0 deletions apps/frontend/controllers/IndexController.php
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()
{

}

}

36 changes: 36 additions & 0 deletions apps/frontend/controllers/MyAwesomeTestController.php
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'
));
}

}

27 changes: 27 additions & 0 deletions apps/frontend/plugins/Test.php
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);
}

}
1 change: 1 addition & 0 deletions apps/frontend/views/error/pageNotFound.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2>This is the pageNotFound page!</h2>
27 changes: 27 additions & 0 deletions apps/frontend/views/index.phtml
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>
6 changes: 6 additions & 0 deletions apps/frontend/views/index/index.phtml
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>
1 change: 1 addition & 0 deletions apps/frontend/views/myAwesomeTest/mySuperTest.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h2>This is the view for mySuperTestAction!</h2>
6 changes: 6 additions & 0 deletions config/loader.php
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/'
));
8 changes: 8 additions & 0 deletions config/modules.php
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'
)
));
33 changes: 33 additions & 0 deletions config/services.php
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();
};
Loading

0 comments on commit ffc9e85

Please sign in to comment.