zend-framework,zend-navigation,zend-auth,zend-acl , Zend Navigation Multiple ACL roles

Zend Navigation Multiple ACL roles


Tag: zend-framework,zend-navigation,zend-auth,zend-acl

I am trying to create an ACL where users may have different roles in different departments.

The user is given a role in the form of role::guest or role::user depending if they are logged in. This is their userRole. (There is also a role::superuser that has access to all departments).

I have also added departmental roles to the ACL in the form of department::role (Eg. bookings::user). This is their departmentRole.

The users departmental roles are stored in the Zend_Auth identity.

The access control part works by extending Zend_Acl and over-riding the isAllowed function. This successfully allows or denys each user.

public function isAllowed($role = null, $resource = null, $privilege = null)
    $identity = Zend_Auth::getInstance()->getIdentity();

    $userRole = $identity->role;
    $departmentRoles = $identity->departmentRoles; 

    if (parent::isAllowed($userRole, $resource, $privilege))
        return parent::isAllowed($userRole, $resource, $privilege);
        else    {
                foreach ($departmentRoles as $departmentRole)
                    if(parent::isAllowed($departmentRole, $resource, $privilege))
                        return true;

    return false;       

The problem I am having is that Zend_Navigation requires an instance of the Acl and a single user role. My view script which builds the navigation menu uses $this->navigation()->accept($page) which only validates against the single user role.

How can I have multiple Acl roles for each user and have Zend_Navigation display menu items that they have access to?

If there is a better / different / correct approach to this please share.



The fact that this approach meant over riding a core function in isAllowed() got me thinking this can't be the correct way to do this.

Now, in my ACL model I fetch all users, departments and associations and loop through creating an array for each user made up of their various roles within their relevant departments. I then create one role for each user and inherit the roles in the array previously created.

This is working well up to now and also means I can also add the users as resources and allow the relevant admin and department managers rights to amend their details etc.

It also means that I can pass a single role to Zend_Navigation and the menu structure should be relevant to their department roles.


IMHO having multiple ACL roles for single user looks like anti-pattern. Zend_Navigation rules are binded to (multiple) resources for single role which makes perferct sense. What are your constraints that forbids you to allow resources for your (department) roles? You can always use inheritance for your ACL roles.

If you prefer having multiple roles for single user, you might need to have separate ACL rules.




Pimcore multilanguage site static route

I've just recently started working with Pimcore in my work and I'm now on a project consisting of three languages each in their seperate tree. Today the sites URL is my-site.com/LANGUAGE/sub-page For example: my-site.com/se/about But what we would want to have is LANGUAGE.my-site.com/sub-page. For example: se.my-site.com/about I've tried using the...

zend framework 2 nested module structrue in one main module

I am trying to create a app using zend framework 2. Have used structure as follow. Getting error class not found. Trying to created nested sub module login inside a main module called album. I have following structure: Album - src - Album - Controller - AlbumController.php - Form -...

Zend framework - how can i update the row if status field and id match?

How to updates the status='ok' only when status is NULL or done or notdone and id matches? $this->db->update('table1', array('status' => 'ok'), array('id=?' => 55)); ...

How to route pages using text instead of IDs?

Currently, my Zend application routes using the URL: example.com/news/12 Selects the news with ID 12 to display on page. But the client wants to use only text, example: example.com/news/man-dies-after-burning-himself Does someone knows how can it be done?...

ZF2 - Display image in view based on full path

I have managed to upload image file in ZF2 and store full path in the database. Path looks like this: /home/ubuntu/NetBeansProjects/project/data/upload/event_5554a7b600c0f.jpg Project structure is a Zend Skeleton application: project data upload event_5554a7b600c0f.jpg module public In my view I call: <img src="<?php echo $event->getImage(); ?>" class="img-thumbnail" alt="<?php echo $event->getTitle(); ?>" width="304"...

Is it possible to set a separator for Zend Framework 2 form rows or display them in paragraphs?

I have this for a form $this->add(array( 'name'=>'username', 'type'=>'Text', 'options'=>array( 'label' => 'Username', ) )); $this->add(array( 'name'=>'password', 'type'=>'Password', 'options'=>array( 'label' => 'Password', ) )); and echo $this->formCollection($form); This are obviously just the relevant parts of the code. The output is as follows: <fieldset ><label><span>Username</span><input type="text" name="username"...

PHP - how to send png or jpg email attachment?

I am using mandrillapp for mailing using following method. But i need to send JPEG or PDF or PNG scan copy from scanner. How can i do that please? public static function sendBcc($from, $to, $subject, $htmlBody, $bcc = '', $bcc1 = '', $utype = '') { $bcc = '', $bcc1...

ZF Error ZF tool setup

Zend 1.9.1 so I get this error Blockquote ***************************** ZF ERROR ******************************** In order to run the zf command, you need to ensure that Zend Framework is inside your include_path. If you are running this without Zendframework in your include-path, you can alternatively set one of two enviroment variables to...

Wrong datatype for referenced entity on Doctrine ObjectSelect

I have a form which uses Doctrine's ObjectSelect to make a dropdown $this->add(array( 'name' => 'category', 'type' => 'DoctrineModule\Form\Element\ObjectSelect', 'options' => array( 'label' => 'Category', 'object_manager' => $em, 'target_class' => 'Blog\Entity\Category', 'property' => 'name' ), 'attributes' => array( 'required' => true ) )); the issue I have, is that this...

Doctrine2: Lazy loading fails and I have to re-initialize the class

I have three entities wallpost, albums and photos. wallpost has many to one relationship with albums. album has one to many relationship with photos. When I post photos on my wall, the data goes into all three tables. One record in wallpost, one in album and multiple in photos. Now...

Manipulate value in Zend_Registry

I have an array that I write into Zend_Registry: Zend_Registry::set('myArray', $myArray); Now I want to add a new value to that array. I know that Zend_Registry is not a good choice at all and I know that it is kind of read-only. But is there any way to update it?...

Transfert a Zend Project to Symfony

I have a project made using Zend. My boss asked me to change the technology to Symfony 2.7. Is there a way to transfer the project ? Or to take some files into Symfony ? Or should I begin all the project from scratch using Symfony ? Thanks !...

Get Google Plus Images Using Zend Framework 1 Gdata

I've been searching for an answer for this for quite some time now. I've looked into the other questions here but couldn't find a relevant one to my situation. Googling the question wasn't helpful as well. Basically, I am using ZF1's Gdata class to access the photos api. This was...

ZendX Console Process posix functions

I am catch the follow exception in my code: ZendX_Console_Process_Exception' with message 'posix_* functions are required What's posix function is need for it work right? Thanks...

Zend Skeleton Application album tutorial 404

As far as I can see I've followed the Zend skeleton application tutorial to the letter (I actually went through it twice with the same result) but when I try to access zf2-tutorial.localhost/album I get the following error: A 404 error occurred Page not found. The requested URL could not...

Zendframework(1.12.11) view helper not found in phpunit

I have following directory structure for view helper in my zendframework project --application --views --helpers --Test.php and configuration setting in application.ini is resources.view.helperPath = APPLICATION_PATH "/views/helpers" and configuration in Bootstrap.php is $view->setHelperPath(APPLICATION_PATH . "/views/helpers/"); in Test.php file naming convention is class Zend_View_Helper_Test extends Zend_View_Helper_Abstract {} and I am using helper...

Zend paginator with AJAX

I have multiple albums listed on a page, next to each album are listed reviews about the album. Essentially this means there are many reviews about many albums on a single page. What would be the best approach to paginate each review section for each album? For example so each...

Overriding ZF2 global/local config: unsetting

I've run into a problem where my local config overrides global but I need local to remove not just override. E.g. // global.php 'mail_transport' => [ 'type' => 'Zend\Mail\Transport\Smtp', 'options' => [ 'host' => 'smtp.gmail.com', 'port' => 587, 'connectionClass' => 'login', 'connectionConfig' => [ // ... ], ], ], //...

Zend_Pdf how to reduce the loading time of images?

I built an pdf document which is based on database records of 2 related tables. The mastertable contains shopdata with logos. In the records I of course don't save the image itself, but only the pathinfo. The detailtable just contains meeting dates, no problems with this one. If I start...

Zend Framework 2 - Sending form using Zend\Mail

So i'm making a contact page. Of course it will have a form, which needs to be sent. I made the class to send email: <?php namespace Site\Mail; use Zend\Mail\Message; use Zend\Mail\Transport\Sendmail; class SendEMail { public function SendEMail($to, $from, $subject, $body) { $message = new Message(); $message->addTo($to) ->addFrom($from) ->setSubject($subject) ->setBody($body);...

is not null condition in zend framework 2

I am new to zf and I've started working with zf2, I don't find much documentation for the syntax and all. My issue is how to write is not null condition in zf2 syntax. $select->where->notEqualTo('pe_name', ''); I've written for not equal to, now I need for is not null. I...

Content type-error when using Zend_Http_Client

I'm trying to send data to Google Analytic's collector with Zend_Http_Client and POST. I have an array $postParams that's including my tracking-ID, cid and hit types and I add the values of this array to my client via setParameterPost(). Here's the relevant part of my Action: $client = new Zend_Http_Client('https://ssl.google-analytics.com/debug/collect');...

Zend Framework 2 Cache filesystem

I've been using the filesystem adapter for cacheing data. E.g.. $cache = StorageFactory::factory(array( 'adapter' => array( 'name' => 'filesystem' 'options' => array('ttl' => 1800, 'cache_dir' => './data/cache'), ), )); But when using the getItem() function AFTER the TTL clocks over it returns false on success etc, which it should... However,...

File upload form validation invalid

Current form: $main = new Zend_Form_SubForm(); $kids = new Zend_Form_SubForm(); $number = $main->addElement(... attribs and so on ...); $this->addSubForms(array('main'=>$main,'kids'=>$kids)); When I'm adding this file upload fields to my form: for($index = 1; $index <= 10; $index++) { $name = 'Image'.$index; $label = 'Image'.$index; $image = new Zend_Form_Element_File($name); $image->setLabel($label) ->addValidator('Count', true,...

Validation for Add screen not working but it working in edit screen with same code

I am learning Zend framework and currently I have created add, update , delete functionality for country name and continent name and it is working perfectly. I have set validation by $name->setRequired('true'); and $continent->setRequired('true'); in my form.php. Validation is working in edit form but it return error 'An error occurred'...

Zend 1 Redirect to controller from library

$this->_helper->redirector('save', 'index', 'report', $params); This does not work when i use it from a library file It says Fatal error: Call to undefined method Mylib::getHelper(). But When used from controller it works properly. Can any guide me with code what I need to do?...

Fetch the maximum value of a field having same id in php

Here's my code,I need to return all the InstallmentDate's along with the return data,the issue here is I have same OrderInstallmentDetailsId for multiple InstallmentDate's. $select = $this->select() ->setIntegrityCheck(false) ->from(array('j' => DB_TABLE_PREFIX . 'finance_journal'), array( '*', 'JournalCreatedDate' => 'CreatedDate' )) ->join(array('jr' => DB_TABLE_PREFIX . 'finance_journal_reference'), 'j.JournalId = jr.JournalId', array( 'totalDebitAmount' =>...

Zend Framework 2 routing error: resolves to invalid controller class or alias

I'm trying to learn Zend Framework 2 and I have their skeleton application up and running. In order to access it I visit http://localhost:8080/. When visiting that link it displays their generic Zend page. What I want to be able to do is visit http://localhost:8080/application/test and have it bring me...

Zend date validator fail for format dd-mm-yyyy

I have the following code: <?php $dateString = '12.12.12'; $dateCheckArray['format'] = 'dd-mm-yyyy'; $validator = new Zend_Validate_Date($dateCheckArray); if ($validator->isValid($dateString)) { echo 'valid'; } else { echo 'invalid'; } The code works ok for most formats, but for the one specified it fails when using a . date instead of a -...

Object of class Zend_Db_Table_Row could not be converted to string

I get the error message in the title when I run the following: $year = date('Y'); $month = date('n'); $day = date('j') - 3; $week = date('W') - 1; $select = "SELECT IF( station_name = '', 'Unknown', station_name ) station_name, station_name as db_name, sum(case when year(print_date) = $year then print_pages...

Uninstalling php 5.3 in ubuntu 14.04

I have installed php 5.3 manually by executing commands like make & make install. But I need to upgrade it to v5.5 therefore I deleted all the directories related to php5 using sudo command. But when I run php -v Still I am getting PHP 5.3.29 (cli) (built: Jun 8...

Password protecting Apigility admin UI without htpasswd

I was being searching to password protect apiglity admin ui without using htpasswd, but i did not got any information about. Can anybody help me out with this? Thanks in advance...

Bootstrap of Zend Module is not loading

I am new in working with zend so I am facing this problem from the past two days. I have searched a lot but still can not find any solution. Possible duplicate of Zend Module Bootstrap does not load but it still can not solve my problem. In my User...

Error in Array comparison in php

Below are the sample arrays I'm Comparing. Table 1 $csvData= ( [0] =&gt; Array ( [Account Number] =&gt; 1.01100156278101E+15 [Posting Date] =&gt; 2014/07/08 [Value Date] =&gt; 2014/07/08 [Description] =&gt; Cash Withdrawal by Cheque-173320--TT1421957901 [Debit Amount] =&gt; 2000 [Credit Amount] =&gt; [Running Balance] =&gt; 388392.62 ) [1] =&gt; Array ( [Account...

zend 1 xsd validation

I am building a simple API end-point in ZF1 and got to the stage of XML validation. I could not find it anywhere in Zend documentation, so maybe someonehas come accross this before: Does Zend Framework 1 has any kind of library or wrapper for validating XML against XSD? or...

Understanding bootstrap, config.php, application.ini

I´m still beginner with Zend Framework. If I read different articles I wonder which are the differences between the three configuration files, bootstrap.php, config.php and application.ini. I only use the application.ini, my bootstrap so far ist empty (of course it is called in my index.php), at the moment I don´t...

controller action not found on production server

In my development area (wamp) everything works fine. Today I uploaded my whole project to my production webspace. I seems like in the production area, some paths are lost. First I saw that in my start layout (ZEND_Layout) my pictures aren't found. So I needed to change the paths to...

Zend InputFilter requires intl PHP extension?

I am setting up some filters and validators for my form, but when I submit it, this error appears: "Zend\I18n\Filter component requires the intl PHP extension". Is this because of the Alnum and Alpha validators ? Code: public function getInputFilter() { if (!$this->inputFilter) { $inputFilter = new InputFilter(); $inputFilter->add(array( 'name'...

How to get all available languages from Localized Fields in pimcore?

I'm a little bit stuck with this: I have a controller where I'm collecting all available languages for an object in pimcore. Right now I simply take a Localized Field from that object, run through it via foreach and fill an array with the Localized Fields's keys. So I get...

Failed installation of zend-escaper with Composer

I'm trying to install zend-escaper but I'm getting this error: This is strange as my PHP version (from phpinfo()) is 5.5.19, the message claims it is 5.3.5(!) which should satisfy the requirement anyway. My ZF version is 1.12.13 I'm using PHP Storm Can anyone help please? Thanks Tomasz...

Socialengine addon Advanced Events Plugin v4.8.8p2 throwing errror on create

I've got a site set up with the base Socialengine setup going. I've installed most of the SocialEngineAddon suite of plugins, and for some reason, the Advanced Events plugin throws this error when I try and create one ie: example.com/appeals/create I've tried renaming back to the default site-event, but the...

Zend File Create folder while uploading

With this form element I'm uploading a file: $element = new Zend_Form_Element_File('foo'); $element->setLabel('Upload Image1:') ->setDestination('/var/www/upload'); $element->addValidator('Count', false, 1); $element->addValidator('Size', false, 102400); $element->addValidator('Extension', false, 'jpg,png,gif'); $form->addElement($element, 'foo'); This requires that the folder is already existing. How can I add an option, that the folder is beeing created, but only if a...

Get the cid for Google Analytics in PHP/Zend Framework

I want to track the usage of an API. So I'm using Zend_Http_Client to send POST-parameters to Google Analytic's collector. The Google developers-page tells me, that I have to send a cid (Anonymous Client ID). But how can I send it via PHP when it is part of the _ga-cookie?...

Pass array on url using zend framework 2 routes

I have a web app that lets user make multiple searches and show the results of that searches all on the same page. Here's a basic structure: Search 1 - Attribute 1 = X - Attribute 3 = Y Search 2 -Attribute 2 = Z All these results are loaded...

Zend And YouTube Not Deleting Videos

Until yesterday I could delete YouTube videos using Zend framework. I was using this code: $httpClient = Zend_Gdata_ClientLogin::getHttpClient( $username, $password, 'youtube', null, 'MySite', null, null, 'https://www.google.com/accounts/ClientLogin'); $yt = new Zend_Gdata_YouTube($httpClient, '', '', $myDevKey); $vid = $yt->getVideoEntry($myVidID, null, true); $yt->delete($vid); Now I am getting this error: Expected response code 200, got...

How to send field name for required true validation in zend

Here is what my form field, $this->addElement( 'text', 'title', array( 'placeholder' => 'Title', 'class' => 'form-control', 'required' => true, 'filters' => array( 'StringTrim' ), 'autocomplete' => 'off', ) ); I Simply need the error string like: Title is required and can't be empty....

Zend 1 3d party NameSpaces autoload don't working

I'm trying to implement Amazon WebServices PHP SDK into my Zend 1 project, but it seems to fail loading the classes. I have got the library into library/Eplan/AmazonCloudSearch and after investigation it seems that in order to be able to load the namespace I need to call the registerNamespace method...

How to manage Zend session save handler using Zend?

I want to save zend session in memcache rather than files bases session management. I have correctly added memcache.dll file in Windows 8 x64 system and check that memcache is working fine and have also installed memcached and windows services showing memcached Server running. I have searched so far for...

PHP ZF2 Mysql has gone away

Hi I have a php daemon that handle request from rabbitmq After a day, it can no longer execute due to error MySQL has gone away. PHP Warning: PDOStatement::execute(): MySQL server has gone away in /var/www/daemon/www/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Driver/Pdo/Statement.php on line 239 PHP Warning: PDOStatement::execute(): Error reading result set\'s header in /var/www/daemon/www/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Driver/Pdo/Statement.php on...

Php Mysql select query not working

The below query results in the following error: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'AccountId' in where clause is ambiguous $select = $this->select() ->from(array('finance_account' => DB_TABLE_PREFIX . 'finance_account'), array( 'AccountId', 'ParentAccountId', 'AccountGroupId', 'AccountPath', 'AccountCode', 'AccountName', 'Description' )) ->joinLeft(array('ac' => DB_TABLE_PREFIX . 'customer'), 'finance_account.AccountId = ac.AccountId', array()) // using "array_unique()" to...