O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

2.routing in zend framework 3

26 visualizações

Publicada em

http://www.rraducanu.ro

Publicada em: Educação
  • Login to see the comments

  • Seja a primeira pessoa a gostar disto

2.routing in zend framework 3

  1. 1. Routing in Zend Framework 3
  2. 2. • Creati controllerele WelcomeController si HomeController
  3. 3. WelcomeController <?php namespace TestController; use ZendMvcControllerAbstractActionController; use ZendViewModelViewModel; class WelcomeController extends AbstractActionController { public function indexAction() { $viewModel = new ViewModel(); $viewModel->setTemplate('test/welcome/index'); return $viewModel; } }
  4. 4. Module/Test/config/module.config.php …………………………………. return [ 'router' => [ 'routes' => [ 'home' => [ 'type' => Literal::class, 'options' => [ 'route' => '/', 'defaults' => [ 'controller' => ControllerIndexController::class, 'action' => 'index', ], ], ], /////////////////////////////////////////////// 'welcome' => [ 'type' => Literal::class, 'options' => [ 'route' => '/welcome', 'defaults' => [ 'controller' => ControllerWelcomeController::class, 'action' => 'index', ], ], ], /////////////////////////////// …………………………………………………………………………………………….
  5. 5. ……………………………………. 'controllers' => [ 'factories' => [ ControllerIndexController::class => InvokableFactory::class, ControllerWelcomeController::class => InvokableFactory::class, ], ], …………………………….
  6. 6. ……………………………………. 'view_manager' => [ 'display_not_found_reason' => true, 'display_exceptions' => true, 'doctype' => 'HTML5', 'not_found_template' => 'error/404', 'exception_template' => 'error/index', 'template_map' => [ 'layout/layout' => __DIR__ . '/../view/layout/layout.phtml', 'test/index/index' => __DIR__ . '/../view/test/index/index.phtml', 'test/welcome/index' => __DIR__ . '/../view/test/welcome/index.phtml', 'error/404' => __DIR__ . '/../view/error/404.phtml', 'error/index' => __DIR__ . '/../view/error/index.phtml', ], …………………………….
  7. 7. • Creati directorul /module/Test/view/test/welcome si in acesta fisierul index.html in care scrieti: <h1>Welcome!</h1> <br/><br/> <a href="../">Back</a> http://localhost:8080/welcome
  8. 8. WelcomeController ………………… public function contactAction() { $viewModel = new ViewModel(); $viewModel->setTemplate('test/welcome/contact'); return $viewModel; }
  9. 9. Module/Test/config/module.config.php /////////////////////////////////////////////// ‘contact' => [ 'type' => Literal::class, 'options' => [ 'route' => '/contact', 'defaults' => [ 'controller' => ControllerWelcomeController::class, 'action' => 'contact', ], ], ], ///////////////////////////////
  10. 10. ………………………………. 'view_manager' => [ 'display_not_found_reason' => true, 'display_exceptions' => true, 'doctype' => 'HTML5', 'not_found_template' => 'error/404', 'exception_template' => 'error/index', 'template_map' => [ 'layout/layout' => __DIR__ . '/../view/layout/layout.phtml', 'test/index/index' => __DIR__ . '/../view/test/index/index.phtml', 'test/welcome/index' => __DIR__ . '/../view/test/welcome/index.phtml', 'test/welcome/contact' => __DIR__ . '/../view/test/welcome/contact.phtml', 'error/404' => __DIR__ . '/../view/error/404.phtml', 'error/index' => __DIR__ . '/../view/error/index.phtml', ],
  11. 11. • Creati fisierul index.html in directorul: /module/Test/view/test/welcome si in acesta in care scrieti: <h1>This is contact page!</h1> <br/><br/> <a href="../">Back</a> http://localhost:8080/contact
  12. 12. In fisierul index.html din directorul: /module/Test/view/test/index scrieti: <h1 style="text-align: center;"><font color="red">URA!!!</font></h1> <br/><br/> <a href="welcome">Welcome page</a> <br/><br/> <a href="contact">Contact page</a>

×