zend-framework2

ZF2 use database table model in view helper

廉价感情. 提交于 2019-12-07 23:54:30
问题 To show an database count in my layout.phtml I want to use the view helper to render ths count (set in an db field). How do I use my database model in a view helper? Helper: namespace Application\View\Helper; use Zend\View\Helper\AbstractHelper; class CountHelper extends AbstractHelper { protected $count; public function __invoke() { return $this->count(); } public function setTableCount($sm, $myCountTable) { $this->count = $sm->get($myCountTable)->getCount(); return $this->count; } } Module

How to write the ZF2 router script to allow parameters on the default action

人盡茶涼 提交于 2019-12-07 19:47:54
问题 I am trying to get around some of the idiosyncrasies of the routing statements in ZF2. The Album module example suggests the following: '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', ), ), ), ), ), Let’s say, however, that I wanted to

Zend Framework 2 including custom library

99封情书 提交于 2019-12-07 19:13:58
问题 My directory structure is like this: c:\Workspaces\Zend c:\Workspaces\Custom library Custom library is a shared library, which is in use in other applications. It doesn't use namespaces, just old style underscores. I downloaded the ZF2-Restful-Module-Skeleton which i intend to use as a restful server. In the InfoController I have this code: namespace Main\Controller; use Zend\Mvc\Controller\AbstractRestfulController; class InfoController extends AbstractRestfulController { public function

ZF2 Generate navigation using zfcrbac zfcUser and hierarchical role strategy

谁都会走 提交于 2019-12-07 18:52:22
问题 I begin in zf2 and i have to handle Many to Many permissions/roles. Using ZfcRbac. So i make a mapping with User / Hierarchical Role (table name= role) / permissions And i make some guards with deny policy. My guard, mapping, database, are ok. My HierarchicalRole Entity looks like : class HierarchicalRole implements HierarchicalRoleInterface And it's, for now the same as the original given by Bakura. My user Entity looks like this : class User extends ZfcUserEntity implements

Use another module in our custom helper in zend framework 2

為{幸葍}努か 提交于 2019-12-07 18:29:39
问题 I want to use WebinoImageThumb moudle in my custom helper , but when I want to create an instance of this module in helper factories I got this error : Zend\View\HelperPluginManager::get was unable to fetch or create an instance for WebinoImageThumb But I can access to an instance in my controller without any problem. This is the code I get error in : public function getViewHelperConfig() { return array( 'factories' => array( 'ImageLib' => function ($sm) { $WebinoImageThumb = $sm->get(

Zend Framework 2 two templates in one layout?

て烟熏妆下的殇ゞ 提交于 2019-12-07 16:03:50
问题 In each module in my application I'll have a main content section and a sidebar menu. In my layout I have the following... <div id="main" class="span8 listings"> <?php echo $this->content; ?> </div> <div id="sidebar" class="span4"> <?php echo $this->sidebar; ?> </div> My controllers all return a single ViewModel which specifies the content (see below) but how do I get it to also populate the sidebar? public function detailsAction() { *some code to populate data* $params = array('data' =>

ZF2: Active branch for child routes in zend navigation. How?

半世苍凉 提交于 2019-12-07 14:32:08
问题 I have this as route configuration in Zend Framework 2: 'news' => array( 'type' => 'Literal', 'options' => array( 'route' => '/news', 'defaults' => array( '__NAMESPACE__' => __NAMESPACE__ . '\Controller', 'controller' => 'News', 'action' => 'index', 'page' => 1, ), ), 'may_terminate' => true, 'child_routes' => array( 'index' => array( 'type' => 'Segment', 'options' => array( 'route' => '[/:page]', 'constraints' => array( 'page' => '\d+', ), 'defaults' => array( '__NAMESPACE__' => __NAMESPACE_

How to handle multidimensional output with (nested) lists using the Zend\Db\TableGateway with a mapper in Zend Framework 2?

筅森魡賤 提交于 2019-12-07 14:10:28
问题 I'm developing a RESTful ZF2 based application and using a TableGateway implementation (subclass of the Zend\Db\TableGateway ) in combination with a simple mapper for the model, similar to the Album example of the ZF2 manual. Table class <?php namespace Courses\Model; use ... class CourseTable { protected $tableGateway; public function __construct(TableGateway $tableGateway) { $this->tableGateway = $tableGateway; } public function findOnceByID($id) { $select = new Select(); $where = new Where

zf2 insert using $db->insert($table, $data); style

戏子无情 提交于 2019-12-07 11:24:15
问题 Hello is there any way to insert data in a db table using the zf1 style on zf2? $db->insert('tablename', $data); where $data is an associative array contains ( columns , values ) thanks 回答1: To make an insert in zf2: use Zend\Db\Sql\Sql; $sql = new Sql($this->dbAdapter); $insert = $sql->insert('table'); $newData = array( 'col1'=> 'val1', 'col2'=> 'val2', 'col3'=> 'val3' ); $insert->values($newData); $selectString = $sql->getSqlStringForSqlObject($insert); $results = $this->dbAdapter->query(

Using Composer, can dependencies be shared between multiple projects?

我的梦境 提交于 2019-12-07 09:21:19
问题 First of all, I'm a complete newbie to Composer. I've been trying it out since it's a sounds awesome and mainly because Zend Framework 2 uses it. Zend Framework 2 is actually also the reason for this thread. It get the basics of Composer. But with my current server setup I have a request, which I can't seem to figure out if possible. Let me explain. I have multiple Zend Framework 2 projects: /home/morten/sites/Project-1/ /home/morten/sites/Project-2/ /home/morten/sites/Project-3/ All of these