Is it possible to configure routes in a container (empty/non-routing parent)? - model-view-controller

I'm creating an authentication module to deal with the login/logout of users into the website.
I want to keep the paths simple:
https://example.com/login
https://example.com/logout
But, for some functions within the application/module, it would make sense to me to set up the two routes under some kind of parent:
'routes' => array(
'auth' => array(
'type' => 'Literal',
'options' => array(
'route' => '',
),
'may_terminate' => true,
'child_routes' => array(
'login' => array(
'type' => 'Literal',
'options' => array(
'route' => '/login',
'defaults' => array(
'controller' => 'Base\Controller\Authentication',
'action' => 'login',
),
),
'may_terminate' => true,
),
'logout' => array(
'type' => 'Literal',
'options' => array(
'route' => '/logout',
'defaults' => array(
'controller' => 'Base\Controller\Authentication',
'action' => 'logout',
),
),
'may_terminate' => true,
),
),
),
The problem is - without any route in the parent, I can't get a match on either of the child routes (/login and /logout return 404 with routing errors).
If I do put a route in the parent, like /auth then the urls only match as /auth/login and /auth/logout.
I don't want the parent to interfere with routing in other modules - for example, the "home" route at '/' is already defined in a different module and I don't want to replace or modify that.
About the only thing I have found on the internet similar to what I'm trying is a resolved bug report from 2012.
Is there a way to define a non-routing parent that can hold routable children in ZF2 configuration?

'routes' => array(
'auth' => array(
'type' => 'Literal',
'options' => array(
'route' => '/',
),
'may_terminate' => true,
'child_routes' => array(
'login' => array(
'type' => 'Literal',
'options' => array(
'route' => 'login',
'defaults' => array(
'controller' => 'Base\Controller\Authentication',
'action' => 'login',
),
),
'may_terminate' => true,
),
'logout' => array(
'type' => 'Literal',
'options' => array(
'route' => 'logout',
'defaults' => array(
'controller' => 'Base\Controller\Authentication',
'action' => 'logout',
),
),
'may_terminate' => true,
),
),
),

Related

orderby not working on wordpress

I trying to order by this values by a custom field (motor) and this is not working. Can you help me? I use acf to create the custom field. And when I do a var_dump it doesn't recognize the order by the parameter.
$args='';
$args = array(
'post_type' => 'grupoelectrogeno',
'post_status' => 'publish',
'posts_per_page' => '100',
'meta_query' => array(
array(
'key' => 'potencia_continua',
'value' => $postpotencia,
'compare' => 'like'
),
array(
'key' => 'motor',
'value' => $postmotor,
'compare' => 'like'
),
array(
'key' => 'version',
'value' => $postversion,
'compare' => 'like'
),
array(
'key' => 'gama',
'value' => 'industrial',
'compare' => 'like'
),
'orderby' => 'motor',
'order'=>'desc',
),
);

How to have 2 actions to action column in Magento grid?

I've created an action column in my magento grid but I want 2 actions in my action column.
I try this code in my _prepareColumn:
$this->addColumn('action',
array(
'header' => Mage::helper('sterenn_quote')->__('Action'),
'width' => '100px',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('sterenn_quote')->__('Modidier'),
'url' => array(
'base' => '*/*/modifyquotation',
'param' => array('id' => $this->getRequest()->getParam('quotation_id'))
),
'field' => 'id'
),
array(
'caption' => Mage::helper('sterenn_quote')->__('Detail'),
'url' => array(
'base' => '*/*/detail',
'param' => array('id' => $this->getRequest()->getParam('quotation_id'))
),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores'
));
But I obtain this result :
How can I have my two action "Modifier" And "Detail" ?
Thanks for answers !

Yii1: How to force filter list in CGridView to parse html ?

I have a grid, in this grid I have filter. Grid code is:
$this->widget('booster.widgets.TbGridView', array(
'id' => 'sam',
'type' => 'striped bordered condensed',
'dataProvider' => $dataProvider,
'responsiveTable' => true,
'enableHistory' => true,
'filter' => $asset,
'columns' => array(
array(
'name' => 'id',
'header' => '#',
'filter' => false,
'type' => 'text',
),
array(
'name' => 'user',
'header' => 'Registered By',
'type' => 'text',
'value' => '$data["assignedBy"]',
),
array(
'name' => 'createdAt',
'header' => 'Created At',
'type' => 'datetime',
),
array(
'name' => 'serial',
'header' => 'Serial',
),
array(
'name' => 'brand',
'header' => 'Brand',
),
array(
'name' => 'model',
'header' => 'Model',
),
array(
'name' => 'assetType',
'type' => 'text',
'filter' => \wsi\it\model\AssetType::getRepository()->getTypeTree(),
'value' => '$data["assetTypeName"]',
'header' => 'Type',
),
array(
'name' => 'assigned',
'value' => '(isset($data["assignedTo"]))? $data["assignedTo"]:null',
'header' => 'Assigned To',
),
array(
'name' => 'location',
'filter' => \wsi\hr\Facade::getInstance()->getLocations(),
'value' => '$data["locationName"]',
'header' => 'Location',
),
array(
'name' => 'status',
'header' => 'Status',
'filter' => \wsi\it\model\Asset::$statusOptionList,
'value' => '\wsi\it\model\Asset::$statusOptionList[$data["status"]]',
),
array(
'class' => 'booster.widgets.TbButtonColumn',
'template' => '{view} {update} {delete}',
'header' => '',
'buttons' => array(
'update' => array(
'url' => '\Yii::app()->controller->createUrl("asset/create", array("id"=>$data["id"]))',
),
'view' => array(
'url' => '\Yii::app()->controller->createUrl("asset/view", array("id"=>$data["id"]))',
),
'delete' => array(
'url' => '\Yii::app()->controller->createUrl("asset/delete", array("id"=>$data["id"]))',
),
),
),
)
)
);
When Grid is rendered in the browser you can see that the filter list box contains html which is not parsed fully!
I had this problem with Yii-Booster before and I solved it with an option which I passed to that widget ('htmlOptions' => 'encode' => false) and It prevents to be treated as string, so browsers would parse it as space. That code which You can see below does not work for grid filter!
$form->dropDownListGroup($formModel, 'segmentList', array(
'wrapperHtmlOptions' => array(
'class' => 'col-md-6'
),
'widgetOptions' => array(
'data' => $segmentTreeArray,
'htmlOptions' => array(
>>> 'encode' => false, <<<
)
),
'hint' => "Press CTRL to add another item, otherwise others will be deselected",
));
BUT I am sure that I have to pass same "encode" => false to filter list too, I just can not find under what key I should pass it (htmlOptions did not work).

ZF2 How to validate fields inside fieldset?

I have a field in the form like this:
$this -> add(array(
'type' => 'field-set',
'name' => 'meta_properties',
'options' => array(
'label' => "Meta Properties",
),
'elements' => array(
)
));
$meta_fieldSet = $this -> get('meta_properties');
$meta_fieldSet->add(array(
'name' => 'meta_title',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Title',
),
));
$meta_fieldSet->add(array(
'name' => 'meta_description',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Description',
),
));
$meta_fieldSet->add(array(
'name' => 'meta_keywords',
'attributes' => array(
'type' => 'text',
),
'options' => array(
'label' => 'Keywords',
)
));
And in my input filter class I have
$inputFilter -> add($factory -> createInput(array(
'name' => 'meta_title',
'required' => false,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 5,
'max' => 150,
),
),
),
)));
$inputFilter -> add($factory -> createInput(array(
'name' => 'meta_description',
'required' => false,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 5,
'max' => 150,
),
),
),
)));
$inputFilter -> add($factory -> createInput(array(
'name' => 'meta_keywords',
'required' => false,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 5,
'max' => 150,
),
),
),
)));
It is not validating. How to validate InputFilter?
When creating Fieldsets you need to extend \Zend\Form\Fieldset. Try creating a fieldset like this:
<?php
/**
* Fieldset Example
*/
namespace Module\Form;
use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;
use Zend\Stdlib\Hydrator\ClassMethods as ClassMethodsHydrator;
class NewFieldset extends Fieldset implements InputFilterProviderInterface
{
public function __construct()
{
// we want to ignore the name passed and give it our own
parent::__construct('appointment');
// Use the model you are associating with your fieldset here
$this->setHydrator(new ClassMethodsHydrator(false))
->setObject(new MyModel)
->setLabel('My Model');
$this->add(array(
'name' => 'fieldset_item_1',
'type' => 'Select',
'options' => array(
'label' => 'FieldSet Item 1',
)
));
$this->add(array(
'name' => 'fieldset_item_2',
'type' => 'Select',
'options' => array(
'label' => 'FieldSet Item 2',
)
));
}
/**
* Sets up the input filter specification and returns it
*/
public function getInputFilterSpecification()
{
return array(
'fieldset_item_1' => array(
'required' => false,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
),
'fieldset_item_2' => array(
'required' => false,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
),
);
}
}
Then you can use it in your form like this:
$this->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'fieldset',
'options' => array(
'label' => '',
'count' => 1,
'should_create_template' => true,
'allow_add' => true,
'use_as_base_fieldset' => false,
'create_new_objects' => true,
'target_element' => array('type' => 'Module\Form\NewFieldset')
),
));
Now when you perform $form->isValid() in a controller it will validate the fieldset. In addition, you can now make some fancy front-end code to dynamically add and remove fieldsets from the form and they will all get validated.

Zend Framework 2 - BjyAuthorize Entity was not found. in /vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php on line 177

I started a project with Zend Framework 2 and I set up the modules ZfcUser and BjyAuthorize.
The ZfcUser part works correctly but when I active BjyAuthorize an error occurs
Doctrine\ORM\EntityNotFoundException: Entity was not found. in /vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php on line 177
Call Stack
here is my config file :
- comper.json
{
"name": "zendframework/skeleton-application",
"description": "Skeleton Application for ZF2",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"zf2"
],
"homepage": "http://framework.zend.com/",
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "2.3.*",
"zf-commons/zfc-user": "dev-master",
"zendframework/zftool": "dev-master",
"doctrine/doctrine-orm-module": "0.8.0",
"gedmo/doctrine-extensions": "v2.3.9",
"zendframework/zend-developer-tools": "dev-master",
"zf-commons/zfc-user-doctrine-orm": "dev-master",
"zf-commons/zfc-admin": "dev-master",
"bjyoungblood/bjy-authorize": "1.4.0"
}
}
application.config.php
return array(
'modules' => array(
'ZendDeveloperTools',
'ZfcAdmin',
'DoctrineModule',
'DoctrineORMModule',
'ZfcBase',
'ZfcUser',
'ZfcUserDoctrineORM',
'BjyAuthorize',
'Application',
'Fountain',
'Rest',
),
'module_listener_options' => array(
'module_paths' => array(
'./module',
'./vendor',
),
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
),
);
bjyauthorize.global.php
return array(
'bjyauthorize' => array(
'default_role' => 'guest',
'identity_provider' => 'BjyAuthorize\Provider\Identity\ZfcUserZendDb',
'role_providers' => array(
'BjyAuthorize\Provider\Role\Config' => array(
'guest' => array(),
'user' => array('children' => array(
'admin' => array(),
)),
),
'BjyAuthorize\Provider\Role\ZendDb' => array(
'table' => 'role',
'identifier_field_name' => 'id',
'role_id_field' => 'roleId',
'parent_role_field' => 'parent_id',
),
'BjyAuthorize\Provider\Role\ObjectRepositoryProvider' => array(
'role_entity_class' => 'Fountain\Entity\Role',
'object_manager' => 'doctrine.entitymanager.orm_default',
),
),
'resource_providers' => array(
'BjyAuthorize\Provider\Resource\Config' => array(
'pants' => array(),
),
),
'rule_providers' => array(
'BjyAuthorize\Provider\Rule\Config' => array(
'allow' => array(
array(array('guest', 'user'), 'pants', 'wear')
),
'deny' => array(
// ...
),
),
),
'guards' => array(
'BjyAuthorize\Guard\Controller' => array(
array('controller' => 'index', 'action' => 'index', 'roles' => array('guest','user')),
array('controller' => 'index', 'action' => 'stuff', 'roles' => array('user')),
array(
'controller' => array('index', 'static', 'console'),
'action' => array('list', 'manage'),
'roles' => array('guest', 'admin')
),
array(
'controller' => array('search', 'administration'),
'roles' => array('staffer', 'admin')
),
array('controller' => 'zfcuser', 'roles' => array()),
),
'BjyAuthorize\Guard\Route' => array(
array('route' => 'zfcuser', 'roles' => array('user')),
array('route' => 'zfcuser/logout', 'roles' => array('user')),
array('route' => 'zfcuser/login', 'roles' => array('guest')),
array('route' => 'zfcuser/register', 'roles' => array('guest')),
// Below is the default index action used by the ZendSkeletonApplication
array('route' => 'home', 'roles' => array('guest', 'user')),
array('route' => 'home', 'roles' => array('guest', 'user', 'admin')),
array('route' => 'fountain', 'roles' => array('guest', 'user')),
array('route' => 'fountain/add', 'roles' => array( 'admin')),
array('route' => 'fountain/delete', 'roles' => array('admin')),
array('route' => 'fountain/edit', 'roles' => array('admin')),
),
),
),
);
zfcuserdoctrineorm.global.php
return array(
'doctrine' => array(
'driver' => array(
// overriding zfc-user-doctrine-orm's config
'zfcuser_entity' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'paths' => array( __DIR__ .'/../../module/Fountain/src/Fountain/Entity'),
),
'orm_default' => array(
'drivers' => array(
'Fountain\Entity' => 'zfcuser_entity',
),
),
),
),
'zfcuser' => array(
// telling ZfcUser to use our own class
'user_entity_class' => 'Fountain\Entity\User',
'enable_default_entities' => false,
),
);
Anyone have an idea of the origin of this problem?

Resources