Simple Zend Framework 2 Website ?

For programming and general questions on Zend Framework

Simple Zend Framework 2 Website ?

Postby gknitz on Wed Dec 12, 2012 11:29 pm

I setup Zend Framework 2 and the Skeleton Application, went through the Album Application example in the manual and everything works as advertised. So I am now trying to apply all this great knowledge to a real case.

Lets say I want to use Zends power in the future but for now I want a simple six page standard website, no authentication, no database, just simple web pages. So for now I am using Zend as a framework to load in the navigation and layout. What is the best way to do this? The Album example is too complex. Do I use Zend/View? Does someone have a good example of this?

Secondly, is it a good idea to leave the Skeleton Application (/module/Application/..) in-tacked and add a new module (/module/NewApp/...) or is it better to modify the Skeleton Application and use it as a starting point?

Thanks.
gknitz
 
Posts: 3
Joined: Wed Dec 12, 2012 11:26 pm

Re: Simple Zend Framework 2 Website ?

Postby gknitz on Fri Dec 14, 2012 10:30 pm

Solution to Simple ZF2 Website ?

Well I hate to answer my own question but I found a solution though it's hard to know if this is the preferred method used to add simple web pages.

Also, I decided to keep the Skeleton Application module branch and modify it instead of creating a new branch. I just change the word 'Application' to 'Learn' in case I want to update Zend in the future.

1) Created about.phtml and contact.phtml files in the directory, /Learn/view/Learn/index/.
2) Added some pass through code to the IndexController.php

Code: Select all
class IndexController extends AbstractActionController
{
    public function indexAction()
    {
        return new ViewModel();
    }
   
    // START: ADDED STATIC PAGES
    public function aboutAction()
    {
        return array();
    }
   
    public function contactAction()
    {
        return array();
    }
    // END: ADDED STATIC PAGES

}


3) Added the routes to the module.config.php file.

Code: Select all
'router' => array(
        'routes' => array(
            'home' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/',
                    'defaults' => array(
                        'controller' => 'Learn\Controller\Index',
                        'action'     => 'index',
                    ),
                ),
            ),
             
            // START: ADDED STATIC PAGES
            'about' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/about',
                    'defaults' => array(
                        'controller' => 'Learn\Controller\Index',
                        'action'     => 'about',
                    ),
                ),
            ),                 
            'contact' => array(
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'options' => array(
                    'route'    => '/contact',
                    'defaults' => array(
                        'controller' => 'Learn\Controller\Index',
                        'action'     => 'contact',
                    ),
                ),
            ),
            // END: ADDED STATIC PAGES



If anyone knows of an easier way let me know.
Thanks.
gknitz
 
Posts: 3
Joined: Wed Dec 12, 2012 11:26 pm


Return to Zend Framework

Who is online

Users browsing this forum: No registered users and 6 guests