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


Zend Navigation Multiple ACL roles

Question:

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.

Thanks

EDIT:

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.


Answer:

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.

 Zend_View_Helper_Navigation_HelperAbstract::setDefaultAcl($acl);

 Zend_View_Helper_Navigation_HelperAbstract::setDefaultRole($role);

Related:


How to route pages using text instead of IDs?


zend-framework,zend-framework2,zend-route,zend-router
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?...

Object of class Zend_Db_Table_Row could not be converted to string


php,mysql,zend-framework
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...

Zend Skeleton Application album tutorial 404


php,zend-framework,zend-framework2
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...

Zend InputFilter requires intl PHP extension?


php,zend-framework,zend-framework2
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'...

File upload form validation invalid


php,zend-framework
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,...

Manipulate value in Zend_Registry


php,zend-framework
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?...

Zend And YouTube Not Deleting Videos


zend-framework,youtube-api,google-client-login
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...

Bootstrap of Zend Module is not loading


php,zend-framework,autoload
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...

Get Google Plus Images Using Zend Framework 1 Gdata


php,cakephp,zend-framework,google-plus,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...

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


php,zend-framework,formcollection
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"...

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


php,zend-framework,socialengine
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...

How to send field name for required true validation in zend


php,zend-framework,zend-form,zend-validate
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....

Overriding ZF2 global/local config: unsetting


zend-framework,zend-framework2
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' => [ // ... ], ], ], //...

PHP ZF2 Mysql has gone away


php,mysql,zend-framework,zend-framework2
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...

How to manage Zend session save handler using Zend?


php,zend-framework,memcached,zend-session,libmemcached
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...

Zend 1 Redirect to controller from library


php,zend-framework
$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?...

Wrong datatype for referenced entity on Doctrine ObjectSelect


php,zend-framework,orm,doctrine2
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...

Zend Framework 2 - Sending form using Zend\Mail


php,jquery,ajax,zend-framework,sendmail
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);...

Zend date validator fail for format dd-mm-yyyy


php,validation,date,zend-framework
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 -...

Zend_Pdf how to reduce the loading time of images?


zend-framework,zend-pdf
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 paginator with AJAX


jquery,ajax,zend-framework,pagination
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...

controller action not found on production server


php,zend-framework
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 framework - how can i update the row if status field and id match?


php,zend-framework
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)); ...

ZendX Console Process posix functions


zend-framework,zendx
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...

ZF Error ZF tool setup


zend-framework,command-line-interface
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...

Get the cid for Google Analytics in PHP/Zend Framework


php,zend-framework,google-analytics,measurement-protocol
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?...

Zendframework(1.12.11) view helper not found in phpunit


zend-framework,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...

Error in Array comparison in php


php,arrays,zend-framework,foreach,zend-framework2
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...

Password protecting Apigility admin UI without htpasswd


zend-framework,zend-framework2,apigility
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...

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


php,validation,zend-framework,zend-form
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'...

Php Mysql select query not working


php,mysql,zend-framework,zend-framework2
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...

Transfert a Zend Project to Symfony


php,symfony2,zend-framework
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 !...

Uninstalling php 5.3 in ubuntu 14.04


php,zend-framework,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...

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


zend-framework,routing,zend-framework2,zend-framework-mvc,zend-framework-routing
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...

Pass array on url using zend framework 2 routes


php,zend-framework,routes,zend-framework2
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...

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


php,zend-framework,zend-locale,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...

zend framework 2 nested module structrue in one main module


php,zend-framework,zend-framework2
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 -...

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


php,mysql,zend-framework,zend-framework2,zend-db-table
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 1 3d party NameSpaces autoload don't working


php,zend-framework,amazon-web-services,namespaces,autoloader
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...

PHP - how to send png or jpg email attachment?


php,zend-framework
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...

Understanding bootstrap, config.php, application.ini


php,zend-framework
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...

Zend File Create folder while uploading


zend-framework,zend-form
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...

Pimcore multilanguage site static route


php,zend-framework,routing,pimcore
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...

Content type-error when using Zend_Http_Client


php,post,zend-framework,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');...

ZF2 - Display image in view based on full path


php,image,zend-framework,zend-framework2
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"...

Failed installation of zend-escaper with Composer


php,zend-framework,composer-php
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...

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


php,zend-framework,doctrine2
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...

Zend Framework 2 Cache filesystem


php,zend-framework,zend-framework2
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,...

is not null condition in zend framework 2


php,mysql,sql,zend-framework,zend-framework2
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...

zend 1 xsd validation


xml,zend-framework,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...