Install PHP, MySQL, Apache2
$ sudo apt-get update $ sudo apt-get apache2 $ sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt $ sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql $ curl -s https://getcomposer.org/installer | php --May be, install curl if dont have on your systems.
Clone ZendSkeletonApplication and install
$ cd $ mkdir Workspace $ cd Workspace $ git clone git://github.com/zendframework/ZendSkeletonApplication.git $ cd ZendSkeletonApplication $ php composer.phar self-update $ php composer.phar install
Web server setup (use PHP CLI for development env)
$ cd ZendSkeletonApplication $ php -s 0.0.0.0:8080 -t public/ public/index.php
Then, open web browser and point to : http://localhost:8080
Create new module (Album module)
Create the directory structure for the album is as follows:
<?php
namespace Album;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
class Module implements AutoloaderProviderInterface, ConfigProviderInterface
{
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
// __DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
}
Create ZendSkeletonApplication/module/Album/config/module.config.php
<?php
return array(
'controllers' => array(
'invokables' => array(
'Album\Controller\Album' => 'Album\Controller\AlbumController',
),
),
'view_manager' => array(
'template_path_stack' => array(
'album' => __DIR__ . '/../view',
),
),
);
Tell ZendSkeletonApplication that use modules Album Open ZendSkeletonApplication / config / application.config.php and add the line:
<?php
return array(
'modules' => array(
'Application',
'Album', // <-- data-blogger-escaped-add="" data-blogger-escaped-line="" data-blogger-escaped-module_listener_options="" data-blogger-escaped-this=""> array(
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
'module_paths' => array(
'./module',
'./vendor',
),
),
);
Create routes for controller and script views
Add following line to module.config.php
# ZendSkeletonApplication/module/Album/config/module.config.php
// The following section is new and should be added to your file
'router' => array(
'routes' => array(
'album' => array(
'type' => 'segment',
'options' => array(
'route' => '/album[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album\Controller\Album',
'action' => 'index',
),
),
),
),
),
The code above will take on the module Album app with the default index.php page
Create controller
Create AlbumController.php in module/Album/src/Album/Controller/
<?php
namespace Album\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class AlbumController extends AbstractActionController
{
public function indexAction()
{
}
public function addAction()
{
}
public function editAction()
{
}
public function deleteAction()
{
}
}
Create views script for AlbumController
module/Album/view/album/album/index.phtml module/Album/view/album/album/add.phtml module/Album/view/album/album/edit.phtml module/Album/view/album/album/delete.phtml
Test module setup
http://localhost:8080/album => index page http://localhost:8080/album/add => add album page http://localhost:8080/album/edit => edit album page http://localhost:8080/album/delete => delete album page
Screenshots
zend framework zend2


0 comments:
Post a Comment