router dont work in ZF 2beta5 [duplicate] - zend-route

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Zend Framework 2 MVC - Modules Route mapping not working
My router was working in beta4 but isn't working in beta5.
Needed is Locale in url.
Option is namespace/module in url.
In module.config.php
return array(
'router' => array(
'routes' => array(
'default' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/[:locale[/:namespace[/:controller[/:action]]]]',
'constraints' => array(
'locale' => '[a-z]{2}_[A-Z]{2}',
'namespace' => '[a-zA-Z][a-zA-Z0-9_-]*',
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'locale' => 'da_DK',
'namespace' => 'Application',
'controller' => 'index',
'action' => 'index',
),
),
),
), ),
'controller' => array(
'classes' => array(
'index' => 'Application\Controller\IndexController'
),
),
......
)

They did some changes, so it's the controller-part that doesn't work. It has changed name to controllers (with an s), and instead of classes it should be invokables now.
So try:
'controllers' => array(
'invokables' => array(
'index' => 'Application\Controller\IndexController'
),
),
Edit: if this fixed the issue, we actually have a similar question here.

Related

Magento issue with adding validation into multi-select checkbox

I have a form in magento admin panel. In the form i have checkboxes which i can select multiple options or one. The issue is i am unable to put validations for that. Because without selecting any option i can save records. My code is as in below:
$fieldset-> addField('time_ranges', 'checkboxes', array(
'label' => Mage::helper('CheckoutTime')->__('Time Ranges'),
'required' => true,
'class' => 'required-entry',
'name' => 'time_ranges[]',
'values' => array(
array(
'label' => Mage::helper('CheckoutTime')->__('Education'),
'value' => 'education',
),
array(
'label' => Mage::helper('CheckoutTime')->__('Business'),
'value' => 'business',
),
array(
'label' => Mage::helper('CheckoutTime')->__('Marketing'),
'value' => 'marketing',
),
array(
'value' => 'investment',
'label' => Mage::helper('CheckoutTime')->__('Investment'),
)
),
));
Can anyone please tell me how to add validations into this form.
Thank You
Try by changing
'name' => 'time_ranges[]'
to
'name' => 'time_ranges'
This way is correct. There were some issues in other places in my coding. That's why it didn't work early. Or else this is the correct way to do that.

Cakephp Form Validation empty indeces

Okay, so, in short, I'm trying to validate a form, as I've done a million times before with no trouble. However, I'm finding that on logging the validation errors, all the invalidated fields have an index in the validationErrors array but the messages are empty.
Yes, I've definitely set the validation messages in the model so I'm unsure why it's empty.
Here are my model validations:
public $validate = array(
'effective_policy_date' => array(
'date' => array(
'rule' => array('date'),
'message' => 'Invalid date format',
),
'notEmpty' => array(
'rule' => array('notEmpty'),
'message' => 'Policy date required',
),
),
'business_address' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
'message' => 'Business address required',
),
),
'city' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
'message' => 'City required',
),
),
'zip_code' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
'message' => 'Zip code required',
),
),
'state_id' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
'message' => 'State required',
),
),
'contact_person' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
'message' => 'Contact person required',
),
),
'phone' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
'message' => 'Phone number required',
),
),
'email' => array(
'notEmpty' => array(
'rule' => array('notEmpty'),
'message' => 'Email address required',
),
'email' => array(
'rule' => array('email'),
'message' => 'Invalid email format',
),
),
);
Here's the output of the validationErrors array after submitting the form with empty fields:
[AccountsRequest] => Array
(
[effective_policy_date] => Array
(
)
[policy_number_one] => Array
(
)
[policy_number_two] => Array
(
)
[policy_number_three] => Array
(
)
[policy_number_four] => Array
(
)
[business_address] => Array
(
)
[city] => Array
(
)
[zip_code] => Array
(
)
[state_id] => Array
(
)
)
For completeness sake, here's my Form->create array I use in the view and the controller action responsible for handling the form submission:
Form create() method
<?php
echo $this->Form->create(
'Request',
array(
'novalidate' => 'novalidate',
'action' => 'new_request',
'inputDefaults' => array(
'label' => false,
'div' => false,
'error' => array(
'attributes' => array(
'wrap' => 'label', 'class' => 'error'
)
)
)
)
);
?>
Controller action
public function new_request()
{
$this->page_id = 'requester_newform';
if($this->request->is('post'))
{
if($this->Request->saveAll($this->request->data, array('deep' => true, 'validate' => 'only')))
{
$this->Session->setFlash('Request saved successfully', 'flash/success');
}
else
{
$this->Session->setFlash('Could not save request. Please correct validation errors', 'flash/error');
}
}
}
You'll see some indeces in the validation array that aren't in the validationErrors, that's simply because I haven't quite finished converting the raw HTML to CakePHP forms.
Problem: The validationErrors array shouldn't be empty. It should contain the messages for the notEmpty rules and as a result there are empty error validation elements on the Form's frontend. Any ideas about what I'm doing wrong?
Aarg, how annoying. I've figured it out and it's a lesson well learnt.
For anyone having a similar issue in the future, make sure that your input fields conform to the relationships of the current form's Model.
For instance, in this example, my form's model is 'Request'. Request hasMany 'AccountsRequest'. So my form inputs were something like:
AccountsRequest.effective_policy_date
where it should have been
AccountsRequest.0.effective_policy_date
With this change, my model validation messages are now showing without issue.
I'd still love to know, however, why CakePHP even picked up those fields as invalid and further, if it was intelligent enough to pick up those fields as invalid why it didn't give me validation messages.
Oh well.....

creating and managing cache and session in Zend Framwork 2

i just started working with ZF2 ...
i want to initialize cache and session in config file and be able too use it in the application ( every where ) either using service manager or ... i have been searching Google for hours with no lock ... couldn't find anything useful in the documentations and ...
i tried this in module.config.php(Application module):
'service_manager' => array(
'factories' => array(
'cache' => '\Zend\Cache\StorageFactory',
),
),
'cache' => array(
'storage' => array(
'adapter' => 'Filesystem',
'options' => array(
'cache_dir' => __DIR__ . '/../../../data/cache'
),
),
'plugins' => array('WriteControl', 'IgnoreUserAbort'),
'options' => array(
'removeOnFailure' => true,
'exitOnAbort' => true,
'ttl' => 100
),
),
i got this error : While attempting to create cache(alias: cache) an invalid factory was registered for this instance type.
so whats the valid factory ?
so any one can help me out here ?
tanks...
Use a closure as factory instead because Zend\Cache\StorageFactory doesn't implement Zend\ServiceManager\FactoryInterface
'service_manager' => array(
'factories' => array(
'cache' => function () {
return Zend\Cache\StorageFactory::factory(array(
'storage' => array(
'adapter' => 'Filesystem',
'options' => array(
'cache_dir' => __DIR__ . '/../../../data/cache',
'ttl' => 100
),
),
'plugins' => array(
'IgnoreUserAbort' => array(
'exitOnAbort' => true
),
),
));
},
),
)
Btw. clean up your cache configuration and where you get the plugin in WriteControl and the option removeOnFailure from?
I've come to this topic from Google with the same error name but definitely different reason. Error could be caused by file not found error. If you get this error, check your config record
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
and be sure that needed file (mapper in my case) is located in the directory according to upper rules.

Zend Framework 2 - Zend\Mvc\Router\Http\Part - Module Configuration

I am creating a multi lingual application using ZF2.. and cannot determine how to add a part URL which will form the base of each URL regardless of modules.
http://localhost/en/us/application/index/index/
I totally understand how to configure /[:namespace[/:controller[/:action]]] using DI
http://localhost/application/index/index/
http://localhost/guestbook/index/index/
http://localhost/forum/index/index/
What I do not understand is how to configure a Part route which will be the base for all routes.. In ZF1 I used Route Chaining to achieve this..
So I need to configure a Part route of /[:lang[/:locale]] which applies site wide and then let the module configure /[:namespace[/:controller[/:action]]] or any other route necessary..
http://localhost/en/us/application/index/index/
http://localhost/zh/cn/application/index/index/
http://localhost/en/uk/forum/index/index/
I think what you are looking for is the child_routes configuration key. Take a look at how ZfcUser configures it's routing (here): it creates a base Literal route (/user) and then chains the sub-routes (/user/login, etc) onto it via the child_routes array.
I think something like this will do the trick for you:
'router' => array(
'routes' => array(
'myapp' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:lang[/:locale]]',
'defaults' => array(
'lang' => 'en',
'locale' => 'us',
),
),
'may_terminate' => false,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'index',
'action' => 'index',
),
),
),
),
),
),
Then in your controller you could do this to get the lang and locale:
$this->params()->fromRoute('lang');
$this->params()->fromRoute('locale');

Kohana 3.2 : Error reading session data

I'm working on a module (a simple cms) with Kohana 3.2 and i'm getting this exception "Error reading session data."
I'm using native session and the funny thing is if i set a "default" group database connection the error isn't showed... (i'm using a custom connection group and i've set this database connection group to the user,role and user_token models).
here's my config file
auth.php
return array(
'driver' => 'orm',
'hash_method' => 'sha256',
'hash_key' => 'just a test 1',
'lifetime' => 1209600,
'session_type' => 'native',
'session_key' => 'just a test 2',
// Username/password combinations for the Auth File driver
'users' => array(
// 'luca' => 'e12afe0d3ead3d36191d86229d27057d96d9f2e063fe6f3e86699aaab5310d42'
// 'admin' => 'b3154acf3a344170077d11bdb5fff31532f679a1919e716a02',
),
);
session.php
return array(
'native' => array(
'name' => 'session_native',
'lifetime' => 43200,
),
'cookie' => array(
'name' => 'session_cookie',
'encrypted' => TRUE,
'lifetime' => 43200,
),
'database' => array(
'name' => 'session_database',
'encrypted' => TRUE,
'lifetime' => 43200,
'group' => Pencil::db_group(),
'table' => 'sessions',
'columns' => array(
'session_id' => 'session_id',
'last_active' => 'last_active',
'contents' => 'contents'
),
'gc' => 500,
),
);
You set encrypted to true, so you need an encrypt key. In your config/encrypt.php add this:
<?php
return array(
'default' => array(
'key' => 'MY_RANDOM_KEY_I_MADE_UP_ALL_BY_MYSELF',
),
);
I would keep session_key set to 'auth_user' instead of your random key as well. I think key in that circumstance is not the same as a hash key.
Check your logs in application/logs to see if anything else is missing.

Resources