I have the following PHP code:
$hostnameRoute = new Zend_Controller_Router_Route_Hostname(
'subdomain.example.com',
array(
'module' => 'subdomain',
'controller' => 'index',
'action' => 'index'
)
);
$plainPathRoute = new Zend_Controller_Router_Route(
':controller/:action/*',
array(
'controller'=> 'index',
'action' => 'index'
)
);
$router->addRoute('subdomain', $hostnameRoute->chain($plainPathRoute));
Now I would like to have this route in my application.ini
I tried it with this code, but this is not working:
resources.router.routes.subdomain.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.subdomain.route = "subdomain.example.com"
resources.router.routes.subdomain.defaults.module = "subdomain"
resources.router.routes.subdomain.chains.default.route = ":controller/:action/*"
resources.router.routes.subdomain.chains.default.defaults.controller = "index"
resources.router.routes.subdomain.chains.default.defaults.controller = "index"
Does anybody has an idea how to solve this?
resources.router.routes.subdomain.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.subdomain.route = ":module.example.com"
resources.router.routes.subdomain.defaults.module = ""
resources.router.routes.subdomain.chains.index.type = "Zend_Controller_Router_Route"
resources.router.routes.subdomain.chains.index.route = ":controller/:action/*"
resources.router.routes.subdomain.chains.index.defaults.controller = "index"
resources.router.routes.subdomain.chains.index.defaults.action = "index"
Try this
Related
i want to keep album:id on deezer. that is my requete but $resultat_brut_deezer is empty. Why ?
Thank's for your help.
$url_d = 'https://api.deezer.com/search?q=album:%22'.$album_title.'%22%20artist:%22'.$nom_aut.'%22';
$datadeezer =array('index'=>'0','limit'=>'1','output'=>'json');
$options_d = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'GET',
'content' => "&".http_build_query($datadeezer)
)
);
$context_d = stream_context_create($options_d);
$resultat_brut_deezer = file_get_contents($url_d, true, $context_d);
$resultat_json_d=json_decode($resultat_brut_deezer);
well i found it.
$url_d = 'https://api.deezer.com/search?q=album:%22'.$album_title.'%22%20artist:%22'.$nom_aut.'%22';
replaced by:
$url_d = 'https://api.deezer.com/search?q=album:%22'.urlencode($basic['title']->value.'%22');
I have a problem with custom zend router.
this is my cat router
$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$router->addRoute('categories', new Zend_Controller_Router_Route(
'video/k/:id/:title',array(
'controller' => 'video',
'module' => 'default' ,
'action' => 'k',
'id' => '',
'title' =>''
)
));
$params = Zend_Controller_Front::getInstance()->getRequest()->getParams();
when i try htttp://dev.dummy.com/video/k/1/foo works fine but
$this->url(array_merge($params, array('order' => 'title'))) or
$this->url(array_merge($params, array('order' => 'title')),'categories')
$this->url(array_merge($params, array('order' => 'title')),'categories', true)
doesnt return htttp://dev.dummy.com/video/k/1/foo/order/title
still returning htttp://dev.dummy.com/video/k/1/foo.
Hope this help.
Thanks.
Try setting the third parameter $reset of the url-helper to true:
$this->url(array_merge($params, array('order' => 'title')), 'categories', true)
This will reset the default parameters.
(Documentation at http://framework.zend.com/manual/1.12/en/zend.view.helpers.html#zend.view.helpers.initial)
When doing the array_merge, the integer keys will be reset to start from beginning. Just append your array instead of the array_merge:
$router->addRoute('categories', new Zend_Controller_Router_Route(
'index/test/:id/:title',array(
'controller' => 'index',
'module' => 'default' ,
'action' => 'test',
'id' => '',
'title' => ''
)
));
echo $this->url(array('order' => 'title'));
Tried it with http://dev.dummy.com/video/k/1/foo and http://dev.dummy.chom/video/k/1/foo/order/title/. In both cases, the url helper output was - htttp://dev.dummy.com/video/k/1/foo/order/title
I want to add a route in my Zend Framework application.
I want a route like this:
example.com/modulename/titleofthearticle-12
who redirect to:
example.com/modulename/article/index/id/12
I made this code, but I don't know how to add the module name in the route:
$router = $front_controller->getRouter();
$route = new Zend_Controller_Router_Route_Regex(
'modulename/[a-z\-]*-([0-9]*)',
array('controller' => 'article', 'action' => 'index'),
array(1 => 'id')
);
$router->addRoute('article', $route);
How to add this module name in the route ?
Thanks !
Try:
$router = $front_controller->getRouter();
$route = new Zend_Controller_Router_Route_Regex(
'modulename/[a-z\-]*-([0-9]*)',
array(
'module' => 'modulename',
'controller' => 'article',
'action' => 'index'),
array(
1 => 'id'
)
);
$router->addRoute('article', $route);
I have situation with Zend route & $this->url method
IN my bootstrap.php I have few routes as
$route = new Zend_Controller_Router_Route(
'dashboard',
array(
'action' => 'index',
'controller' => 'index',
'module' => 'dashboard',
'isAdmin' => true
)
);
$router->addRoute('dashboard', $route);
$route = new Zend_Controller_Router_Route(
'logout',
array(
'action' => 'logout',
'controller' => 'index',
'module' => 'main',
'isAdmin' => true
)
);
$router->addRoute('logout', $route);
$route = new Zend_Controller_Router_Route(
'manage-users',
array(
'action' => 'list',
'controller' => 'index',
'module' => 'main',
'isAdmin' => true
)
);
$router->addRoute('manage-users', $route);
$route = new Zend_Controller_Router_Route(
'edit-user/:id',
array(
'action' => 'edit',
'controller' => 'index',
'module' => 'main',
),
array('id' => '[0-9]+')
);
$router->addRoute('edit-user', $route);
$route = new Zend_Controller_Router_Route(
'/manage-subcat/:ident',
array(
'action' => 'index',
'controller' => 'subcategory',
'module' => 'category',
'ident' => '',
array(
'ident' => '[a-zA-Z-_0-9]+',
)
)
);
$router->addRoute('manage-subcat', $route);
take a case of last route
in my view when I write
<?php echo $cat->CategoryName ?>
I get url as http://127.0.0.10/manage-subcat
& when I disable the last route in bootstrap & then I write in my view file
<?php echo $cat->CategoryName ?>
I get Url as same http://127.0.0.10/category/subcategory
Ideally I should get http://127.0.0.10/category/subcategory/ident/some-category for this one
& for previous one it should be http://127.0.0.10/manage-subcat/ident/some-category
This code sample is not working with custom routes as well as traditional routes, and I am trying to determine why this sample is not working correctly.
Besides the route declaration formatting error noted by zerocrates, could it be simply a typo in your code?
I notice you use $cat->CategoryName (singular $cat) in one place and $cats->catident (plural $cats) in another.
If passed a null parameter value, the router will omit that parameter from the generated URL.
With this code:
$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$router->addRoute(
'test',
new Zend_Controller_Router_Route(
'/test/:action/:type/:id',
array(
'controller' => 'admin'
)
)
);
http://app/test/param1/param2/param3 -> OK
http://app/test/param1/param2/ -> FAIL
In the second case the application don't recognize param2.
It seems that the application needs the param3 in order to read the param2...
How can I do it?
Thanks!
Test with the code from #RageZ
$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$router->addRoute(
'test',
new Zend_Controller_Router_Route(
'/test/:action/:type/:id',
array(
'controller' => 'admin',
'id' => 0
),
array(
'id' => '\d+'
)
)
);
http://app/test/ -> OK
http://app/test/some -> OK
http://app/test/some/more -> FAIL
http://app/test/some/more/andmore -> OK
Ideas?
try giving a default value to everything
$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$router->addRoute(
'test',
new Zend_Controller_Router_Route(
'/test/:action/:type/:id',
array(
'controller' => 'admin',
'action' => 'index',
'type' => 'sometype',
'id' => 0
),
array(
'id' => '\d+'
)
)
);
Just tried your code in some test project and this fixed it hope it works for you!
You have to provide a default value if the parameter is optional.
$frontController = Zend_Controller_Front::getInstance();
$router = $frontController->getRouter();
$router->addRoute(
'test',
new Zend_Controller_Router_Route(
'/test/:action/:type/:id',
array(
'controller' => 'admin',
'id' => 0
),
array(
'id' => '\d+'
)
)
);
Nothing to do with your question but it's a good practice to use the third param of addRoute. Zend Framework would verify that the parameters value match the format you have specified, in that case I suppose id is an integer.