aftdev / aftzend
Zend Library Addons
Requires
- php: >=5.5
- aftdev/jquery: 1.0.*
- rwoverdijk/assetmanager: 1.*
- zendframework/zend-cache: ^2.5
- zendframework/zend-config: ^2.5
- zendframework/zend-console: ^2.5
- zendframework/zend-db: ^2.5
- zendframework/zend-file: 2.*
- zendframework/zend-filter: ^2.6.1
- zendframework/zend-http: ^2.5.4
- zendframework/zend-i18n: ^2.6
- zendframework/zend-log: ^2.7.1
- zendframework/zend-mail: ^2.5
- zendframework/zend-mvc: 2.7.1
- zendframework/zend-navigation: ^2.5
- zendframework/zend-paginator: ^2.5
- zendframework/zend-serializer: ^2.5
- zendframework/zend-session: ^2.6.2
- zendframework/zend-uri: ^2.5
- zendframework/zend-validator: ^2.6
- zendframework/zend-version: ^2.5
- zendframework/zend-view: ^2.6.3
Suggests
- aws/aws-sdk-php: Amazon SDK
This package is auto-updated.
Last update: 2019-09-15 20:48:22 UTC
README
Zend Framework 2 - Custom Library
View Manager - Contexts
Adding possibily for controller action to have contexts - kind of like ZendFramework 1 contextSwitcher
How to Configure:
config file:
['view_manager'] =>
['contexts'] =>
'format' => array(
'layout' => false, // Enable / Disable layout for the context
'suffix' => 'json', // View template suffix action-{suffix}.phtml
'xmlHttpRequest' => true, // True if context should only be activated on Ajax Request
'headers' => array(
'Content-type' => 'application/json',
) // List of headers to add to the response
)
....
Controllers:
Specify what contexts are enabled for each action
class ApplicationController extends Controller{
public $contexts = array(
'action-name' => array('for','json','ajax'),
'other-action' => array('json')
);
...
Controller Plugins:
Context:
$this->context()->getContextInfo(); // returns the name of the current context - false if no context selected
AssetManager
Theme Management
AftZend allow you to create themes for your applications Themes require the "rwoverdijk/assetmanager module
// Theme
'theme_manager' => array(
'default_theme' => 'default',
'custom_theme_path' => false,
'theme_paths' => array('themes'),
'adapters' => array(
'AftZend\Theme\Adapter\Configuration',
),
),
- default_theme: name of the theme that will be used by default
- theme_paths: path of the themes: by default /themes
- custom_theme_path:
you can specify a custom path if you prefer {theme} will be replaced by the name of the theme
e.g: "custom/path/{theme}/config/
- adapters: the adapter that will be used to select the current theme - Right now only one adapter
- AftZend\Theme\Adapter\Configuration that look at the value of "default_theme" in the configuration files
- AftZend\Theme\Adapter\Session: get theme from session variable [TODO]
- AftZend\Theme\Adapter\Route: get theme based from route [TODO]
Theme structure
The theme configuration file (located in /theme/THEME/config.php) will override the application config
return array(
'name' => 'bootstrap',
'inherit' => false, // Theme can inherit other themes
'asset_manager' => array(
'resolver_configs' => array(
'paths' => array(
__DIR__ . '/public',
),
)
),
'view_manager' => array(
'template_map' => array(
'layout/layout' => __DIR__ . '/view/layout/layout.phtml',
'error/404' => __DIR__ . '/view/error/404.phtml
'error/index' => __DIR__ . '/view/error/index.phtml',
),
'template_path_stack' => array(
'bootstrap-theme' => __DIR__ . '/view',
),
),
/*
'view_helpers' => array(
'invokables' => array(
'TestBootstrap' => 'Theme\Bootstrap\View\Helper\Test',
),
),*/
);
Database
Select
New functions
$select->clearAllColumns(): reset all the columns (event the one defined by the joins) $select->addColumn(): add columns to the select statement.
@TODO: filterBy orderBy
Forms
to do
Router
Admin Route
The default admin route is /admin
'admin' => array(
'type' => 'AftZend\Mvc\Router\Http\Admin',
'may_terminate' => true,
'options' => array(
'route' => '/admin'
),
'child_routes' => []
You can add child routes to this admin route . Doing so means that any action will be renamed to adminAction. So if you have a route that points to Controller A - Action "view" then the route will actually point to Controller A - action "adminView"
Extensions
Route to match all the extensions
'route-name' => array(
'type' => '\AftZend\Mvc\Router\Http\Extensions',
'options' => array(
'extensions' => ['js','css'],
'defaults' => array(
'controller' => 'Controller',
'action' => 'index',
),
),
),
This will match any urls that end by .js or .css
Mailer
AftZend\Mailer
Config:
'mailer' => array(
'sandbox' => false,
'defaults' => array(
'from' => array('defaultFrom@email.com' => 'Default From'),
),
'transport' => array(
'type' => 'Sendmail'
),
// Default Layout and View path
'maps' => array(
'default' => array(
'layout/html' => __DIR__ . '/../view/mail/html/layout.phtml',
'layout/txt' => __DIR__ . '/../view/mail/txt/layout.phtml',
'view/html' => __DIR__ . '/../view/mail/missing.phtml',
'view/txt' => __DIR__ . '/../view/mail/missing_txt.phtml'
),
'otherTemplate' => []
)
),
Params:
Sandbox If value is set to an email address then all emails sent by application will be redirected to that address - useful for development
maps Define view paths of your Templates here
Usign Mailer
$mail = $this->getMainServiceLocator()->get('Mailer');
$mail->setTemplateMap('otherTemplate'); // template paths must be defined in your configuration file
$mail->addTo('EMAIL ADDRESS');
$mail->setVariables(
array(
'var1' => 1,
'var2' => 2
)
);
$mail->send();
Transports
Smtp
Gmail Example:
'transport' => array(
'type' => 'Smtp',
'options' => new \Zend\Mail\Transport\SmtpOptions(array(
'host' => 'smtp.gmail.com',
'connection_class' => 'login',
'connection_config' => array(
'ssl' => 'tls',
'username' => 'yourgmailusername',
'password' => 'yourgmailpassword'
),
'port' => 587,
)
)
)
Mandrill
You need to use the "HttpTransport" Transport and Mandrill Service
'transport' => array(
'type' => '\AftZend\Mail\Transport\HttpTransport',
'service' => array(
'class' => '\AftZend\Mail\Service\MandrillService',
'config' => array(
'apiKey' => 'MANDRILL API KEY'
)
)
)
Mailgun
You need to use the "HttpTransport" Transport and Mailgun Service
'transport' => array(
'type' => '\AftZend\Mail\Transport\HttpTransport',
'service' => array(
'class' => '\AftZend\Mail\Service\MailgunService',
'config' => array(
'domain' => 'DOMAIN',
'apiKey' => 'API KEY'
)
)
)
Controller View Models
SearchViewModel
ConfirmationViewModel
FormViewModel
Controller Plugins
Redirect
- toPreviousPage(): toDO
IsConfirmed: toDo
SubLayout: toDo
Cron Jobs Management
Warning: If you do not use the AftUser Module the pages will be publicly available to all
url: /admin/cron Allow Management of cron jobs.
Configure your cron server to execute this action every minutes It should be run by the same user as the Webserver
> php index cron execute
You can setup cron tasks to be run at certain frequencies -> once every X minutes Y hours
Manually execute one task
If you want to setup more complicated rules you need to use your cron job software
You can define the tasks in the database with a frequency set to NULL and use your cron job software to execute the tasks when needed
--uri TASKURI Force execution of a task
> php index cron execute --uri job_2 [--verbose]
Display list of cron tasks installed
> php index cron list
┌──────────────────────────────┬───────────────┬──────────┬───────────────┬──────────────────────────────┬──────────────────────────────┐
│ uri │ Frequency │ Status │ Running ? │ Last execution │ Next execution │
├──────────────────────────────┼───────────────┼──────────┼───────────────┼──────────────────────────────┼──────────────────────────────┤
│ job_1 │ 01:00:00 │ 1 │ 0 │ 2016-06-08 20:00:00+0000 │ 2016-06-08 21:00:00+0000 │
├──────────────────────────────┼───────────────┼──────────┼───────────────┼──────────────────────────────┼──────────────────────────────┤
│ job_2 │ 00:01:00 │ 1 │ 0 │ 2016-06-08 20:52:00+0000 │ next iteration │
├──────────────────────────────┼───────────────┼──────────┼───────────────┼──────────────────────────────┼──────────────────────────────┤
│ job_3 │ NULL │ 1 │ 0 │ 2016-05-08 00:00:00+0000 │ │
├──────────────────────────────┼───────────────┼──────────┼───────────────┼──────────────────────────────┼──────────────────────────────┤
│ job_4 │ 24:00:00 │ 1 │ 0 │ 2016-06-08 00:00:00+0000 │ 2016-06-09 00:00:00+0000 │
└──────────────────────────────┴───────────────┴──────────┴───────────────┴──────────────────────────────┴──────────────────────────────┘
Log Management
Warning: If you do not use the AftUser Module the pages will be publicly available to all
url: /admin/logs Allow admin to see logs saved by application
Cache Management
Warning: If you do not use the AftUser Module the pages will be publicly available to all
url: /admin/cache Allow user to clear different cache defined in the application.
File Management
public / private
Using Doctrine 2
From Database Table to Entity Files
Command Line
./vendor/doctrine/doctrine-module/bin/doctrine-module orm:convert-mapping --namespace="Application\\Entity\\" --force --from-database –filter=”Yourtablename” annotation ./module/Application/src/
./vendor/doctrine/doctrine-module/bin/doctrine-module orm:generate-entities ./module/Application/src/ --generate-annotations=true
Php Script
/aftzend/bin/generate-doctrine-entities-from-db.php (Edit Module Path here)