Zend Framework 1 Routing * Params in Adminurl - php

I got a problem solving an variable Adminurl in Zend Framework 1.
The Route looks fine and should work, it do except if i give parameters.
Thanks for anyone who could help.
Why this will not work?
$adminpath is simple valid string.
'resources' => array(
'router' => array(
'routes' => array(
'backend' => array(
'route' => $adminpath.'/:module/:controller/:action/*'
)
)
)
),
It returns:
http://localhost/cms/admin/AppB/update/activate/moduleName/AppCm
An error occurred
Page not found
Exception information:
Message: Invalid controller specified (admin)
Stack trace:
Request Parameters:
array (
'controller' => 'admin',
'action' => 'AppB',
'update' => 'activate',
'moduleName' => 'AppCm',
'module' => 'App',
)

You have two intersected routes. They are both can parse this URL, but someone parse first, and stops an URL-recognition process. Default route parse URL first and returns
'module' => 'App',
'controller' => 'admin',
'action' => 'AppB',
Try to put defaultRoute initialization
/* #var Zend_Controller_Router_Rewrite $router */
$router->addDefaultRoutes();
/*init of '/:module/:controller/:action/*' route*/
after adding of all other routes .
Sometimes it is important to regulate route priority directly from config. To do this, you can add priority parameter in a routes config, for example:
'routes' => array(
'backend' => array(
'route' => $adminpath.'/:module/:controller/:action/*',
'priority' => 555
),
)
And sort a config by priority before the routes config would add to router ( $router->addConfig call ). In ZF2 route priority param is native.

Related

Zend Framework 2 navigation active class with params

Hi I have create a route like this
'webb' => array(
'type' => 'Segment',
'options' => array(
'route' => '/oferta/[:url1[/:url2][/:url3][/:url4]]',
'defaults' => array(
'controller' => 'webb',
'action' => 'index',
),
),
So my route is looking for paremeters url1 url2 etc
I have created navigation like this (just one item to show)
'page-3' => array(
'label' => 'example',
'route' => 'webb',
'controller' => 'index',
'params' => array('url1' => aa', 'url2' => bb', 'url3' => 'cc'),
)
and when I am rendering it using zend navigation helper everything is working fine despite that the current class of item is not changing to active? Any ideas? could it be done this way or when I am passing params zend navigation will not change class?
Bur url is bulid fine i get something like this /oferta/aa/bb/cc
Please help
Remove controller key from navigation array and it should work ('controller' => 'index' is wrong anyway).
From zend.navigation.pages.mvc
Note that when using the route property in a page, you do not need to specify the default params that the route defines (controller, action, etc.).

Zend Framework 2, redirecting to route and passing a variable to new controller

I implemented a form for placing new orders in Zend Framework 2 and after submitting the form I should redirect to another route and take the orders.id variable in another controller.
I tried using $this->redirect()->toRoute('confirm', array('param'=>$orderId)); but it is not working at all.
Maybe I do not know how to get that parameter in another confirmAction controller.
Please give me some examples. Thank you very much.
1) Since this is a routing issue, show what you have for the route in the module.config.php file. You might not have the "param" constraint configured properly in your config if I had to guess.
It should look something like this:
'confirm' => array(
'type' => 'segment',
'options' => array(
'route' => '/controller_name/confirm[/][:param][/]',
'constraints' => array(
'param' => '[0-9]*'
),
'defaults' => array(
'__NAMESPACE__' => 'your_namespace', // ex. Application\Controller
'action' => 'confirm', // or whatever action you're calling
'controller' => 'controller_name' // ex.
),
),
),

Unable to use console in ZF2

I'm trying to access a function from my controller, using the console. It's a small application, so i only have one controller, 'IndexController'. The action i'm trying to reach is the 'buildSchemeAction'.
As i understand, you have to add routes in your "module.config.php" file, which i did as followed :
return array(
'console' => array (
'router' => array (
'routes' => array (
'build-scheme' => array (
'options' => array (
'route' => 'build-scheme',
'defaults' => array (
'controller' => 'Application\Controller\Index',
'action' => 'build-scheme'
)
)
)
)
)
), ..//
My Controller function looks like this :
public function buildSchemeAction()
{
// logic here
}
When i enter the following in console :
php index.php build-scheme
i get :
Zend Framework 2.2.5 application
Usage:
Reason for failure: Invalid arguments or no arguments provided
I've been searching the web, but can't find anything. Am i missing something?
I just found out why it didn't work. I had my console routes at the top of my module.config file, while this was at the very bottom :
// Placeholder for console routes
'console' => array(
'router' => array(
'routes' => array(
../
),
),
),
Totally overlooked it, since it was there by default.

ZF2 toRoute with https

We're using Zend Framework 2 and use toRoute within our controllers to redirect to various locations, for example $this->redirect()->toRoute('home');.
Is there anyway to have this redirect to https instead of http using this method or an alternative method?
Thank you!
In order to use https in your route you need to use the Zend\Mvc\Router\Http\Scheme router. Specifying the configuration for such route is not very different from the other routes. You need to specify the route type as Scheme and add an option 'scheme' => 'https' in your router configuration in module.config.php.
Here is an example:
return array(
'router' => array(
'routes' => array(
'routename' => array(
'type' => 'Scheme', // <- This is important
'options' => array(
'route' => '/url',
'scheme' => 'https', // <- and this.
'defaults' => array(
'__NAMESPACE__' => 'MdlNamespace\Controller',
'controller' => 'Index',
'action' => 'someAction',
),
),
),
// the rest of the routes
),
),
// the rest of the module config
);
If you have the route routename configured like above, this: $this->redirect()->toRoute('routename'); will work.
See this for reference to the ZF2's manual.
Hope this helps :)
Stoyan

Zend Framework 2 Console Routes

I'm trying to define some console routes for my ZF2 application as described here http://packages.zendframework.com/docs/latest/manual/en/modules/zend.console.routes.html
in the module config I have:
'console' => array(
'router' => array(
'routes' => array(
'user-set-password' => array(
'options' => array(
'route' => 'user password <username> <password>',
'defaults' => array(
'controller' => 'User\Profile',
'action' => 'setpassword'
),
),
),
),
),
),
but it seems to never match the route as it always prints the usage information. also simple routes like just 'test' won't be matched.
(when I write some crap into the route parameter, the execution fails with an Zend\Mvc\Router\Exception\InvalidArgumentException so it recognizes the console route when loading the module)
is it my fault or maybe a bug in the latest zf2 version?
I just found the solution in an inconsistent interface for the route definitions:
it works if you provide the following schema for the controller:
'controller' => 'User\Controller\Profile'
would be better to be able to define it in the same way as http routes:
'defaults' => array(
'__NAMESPACE__' => 'User\Controller',
'controller' => 'Profile',
'action' => 'setpassword',
),
just opened an issue for that: http://framework.zend.com/issues/browse/ZF2-515

Categories