I am trying to make a route in the ini file to match the following URLs, but I have been unsuccessful.
/add-announce.html
/add-announce-books-53.html
My route is this:
routes.add_announcement.type = "Zend_Controller_Router_Route_Regex"
routes.add_announcement.route = "/add-announce(-[a-zA-Z_]+)?(-[\d]+)?.html"
routes.add_announcement.defaults.module = announcement
routes.add_announcement.defaults.controller = frontend
routes.add_announcement.defaults.action = add
routes.announcements.defaults.catName = null
routes.announcements.defaults.catId = null
routes.add_announcement.map.catName = 1
routes.add_announcement.map.catId = 2
Maybe because your matches has '-' at the beginning?, Can you try with:
routes.add_announcement.route = "add-announce(?:-([a-zA-Z_]+))?(?:-([\d]+))?.html"
EDIT: I just found the error, you set the mapped values wrong:
routes.add_announcement.map.catName = 1
routes.add_announcement.map.catId = 2
instead you have to do it like this:
routes.add_announcement.map.1 = "catName"
routes.add_announcement.map.2 = "catId"
Also routes.announcements.defaults.catName shouldn't be routes.add_announcement.defaults.catName?
Related
$this->db->select('SUM(status = In Stock)As In Stock,SUM(status = Allocated)AS Allocated,SUM(status = Decommission) as Decommission,SUM(status = In transit)AS In Transit');
// $this->db->from('assets');
$this->db->group_by("assettype,location");
$query = $this->db->get('assets');
Getting syntax error in the above query.
Kindly help
change
$this->db->select('SUM(status = "In Stock")As In_Stock,SUM(status = "Allocated")AS Allocated,SUM(status = "Decommission") as Decommission,SUM(status = "In transit")AS In_Transit');
Not sure if it is possible with ZF 1.11 to do the following
Normal method of displaying a photo
www.mysite.com/photos/display/377486
Where 377486 is the id of a photo within mysql and can be any integer
Is it possible to have the url shortened so I get the same with
www.mysite.com/photos/377486
If this is possible what is this technique/method called?
Many thanks
No, You need 2 different route.
You can test :
routes.photos.type = "Zend_Controller_Router_Route_Regex"
routes.photos.route = "photos/display/(\d+)"
routes.photos.defaults.controller = "photos"
routes.photos.defaults.action = "display"
routes.photos.map.1 = "id"
routes.photos.reverse = "books/%d"
routes.photos_short.type = "Zend_Controller_Router_Route_Regex"
routes.photos_short.route = "photos/(\d+)"
routes.photos_short.defaults.controller = routes.photos.defaults.controller
routes.photos_short.defaults.action = routes.photos.defaults.action
routes.photos_short.map.1 = "id"
routes.photos_short.reverse = "books/%d"
How can I optimize all of these routes into one. As we do in .htaccess file.
routes.addemails.type = "Zend_Controller_Router_Route_Regex"
routes.addemails.route = "campaign/email/add"
routes.addemails.defaults.module = campaignManagement
routes.addemails.defaults.controller = Email
routes.addemails.defaults.action = add
routes.updateEmail.type = "Zend_Controller_Router_Route_Regex"
routes.updateEmail.route = "campaign/email/edit/?([a-zA-Z0-9_-]+)?"
routes.updateEmail.defaults.module = campaignManagement
routes.updateEmail.defaults.controller = Email
routes.updateEmail.defaults.action = edit
routes.updateEmail.map.key = 1
routes.delEmail.type = "Zend_Controller_Router_Route_Regex"
routes.delEmail.route = "campaign/email/delete/?([a-zA-Z0-9_-]+)?"
routes.delEmail.defaults.module = campaignManagement
routes.delEmail.defaults.controller = Email
routes.delEmail.defaults.action = delete
routes.delEmail.map.id = 1
I've not set up a route using a config file, but at a glance try:
routes.emails.route = "campaign/email/(add|edit|delete)/?([a-zA-Z0-9_-]+)?"
routes.emails.map.action = 1
routes.emails.map.id = 2
I am assuming that the map.* are the variables in the url (so action is the first bit of regex, with id being the second bit of regex. Correct me if I'm wrong).
I am trying to define routes as below with an INI file for the Zend Framework:
http://api.example.com/servicename/{version}/users/:userid/items/:itemid
routes.host.type = "Zend_Controller_Router_Route_Hostname"
routes.host.route = "api.example.com"
routes.host.chains.api.type = "Zend_Controller_Router_Route_Static"
routes.host.chains.api.route = "servicename/v1"
routes.host.chains.api.defaults.controller = "servicename-v1-api"
routes.host.chains.api.defaults.action = "index"
routes.host.chains.api.chains.users.chains.user.type = "Zend_Controller_Router_Static"
routes.host.chains.api.chains.users.route = "users"
routes.host.chains.api.chains.users.defaults.controller = "users"
routes.host.chains.api.chains.users.defaults.action = "index"
routes.host.chains.api.chains.users.chains.user.type = "Zend_Controller_Router_Route"
routes.host.chains.api.chains.users.chains.user.route = ":id"
routes.host.chains.api.chains.users.chains.user.defaults.controller = "user"
routes.host.chains.api.chains.users.chains.user.defaults.action = "index"
...
The host-api route works fine but when I try to reach the other routes, I get the error 'No route matched the request'
The chains.something.chains.somethingelse seems awkward so it probably isn't the correct way to do it. Anyone?
I think I have found how to do it. Basically, you define the parts of each routes with abstract set to true and link them all with routes whose type is set to Zend_Controller_Router_Route_Chain. Something like:
[...]
routes.users.type = "Zend_Controller_Router_Route"
routes.users.route = "users"
routes.users.abstract = "1"
routes.users.defaults.controller = "users"
routes.users.defaults.action = "index"
routes.host-api-users.type = "Zend_Controller_Router_Route_Chain"
routes.host-api-users.chains = "host, api, users"
I am newbie to Zend framework, I am using .ini file to add routes in my application.
I have 2 routes for different modules which
resources.router.routes.news_view.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.news_view.route = "([0-9\-]+)/([a-zA-Z0-9\-]+)\.html"
resources.router.routes.news_view.defaults.module = "news"
resources.router.routes.news_view.defaults.controller = "index"
resources.router.routes.news_view.defaults.action = "view"
resources.router.routes.news_view.map.1 = "date"
resources.router.routes.news_view.map.2 = "title"
resources.router.routes.edu_view.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.edu_view.route = "([0-9\-]+)/([a-zA-Z0-9\-]+)\.html"
resources.router.routes.edu_view.defaults.module = "education"
resources.router.routes.edu_view.defaults.controller = "index"
resources.router.routes.edu_view.defaults.action = "article"
resources.router.routes.edu_view.map.1 = "date"
resources.router.routes.edu_view.map.2 = "title"
the url pattern is like
http://news.mysite.com/27-08-09/sample.html
http://education.mysite.com/27-08-09/sample.html
the problem I face is the last defined route is assigned for both the modules.
can anyone suggest a solution for this.
Hi after much browsing in the web I came up with this solution for my problem
resources.router.routes.www.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.www.route = ":module.findchennai.com"
resources.router.routes.www.defaults.module = "www"
resources.router.routes.www.chains.index.type = "Zend_Controller_Router_Route"
resources.router.routes.www.chains.index.route = ":controller/:action/*"
resources.router.routes.www.chains.index.defaults.controller = "index"
resources.router.routes.www.chains.index.defaults.action = "index"
The above code maps the module with sub domain
resources.router.routes.news.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.news.route = "news.findchennai.com"
resources.router.routes.news.defaults.module = "news"
resources.router.routes.edu.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.edu.route = "education.findchennai.com"
resources.router.routes.edu.defaults.module = "education"
resources.router.routes.edu.chains.list.type = "Zend_Controller_Router_Route"
resources.router.routes.edu.chains.list.route = ":categ/:page"
resources.router.routes.edu.chains.list.defaults.controller = "index"
resources.router.routes.edu.chains.list.defaults.action = "category"
resources.router.routes.edu.chains.list.defaults.page = 1
resources.router.routes.news.chains.list.type = "Zend_Controller_Router_Route"
resources.router.routes.news.chains.list.route = ":categ/:page"
resources.router.routes.news.chains.list.defaults.controller = "index"
resources.router.routes.news.chains.list.defaults.action = "category"
resources.router.routes.news.chains.list.defaults.page = 1
This solves the problem I faced and now could map correctly to the following urls
http://news.mysite.com/27-08-09/sample.html
http://education.mysite.com/27-08-09/sample.html
Still if some one knows how to optimise the above code further, Please let me know.
Do both subdomains call into the same index.php?
If they don't only set the route based on the appropriate sub domain instead of setting both routes in both sub domains.
If they do either read from the $_SERVER['HTTP_HOST'] variable and set the correct route based on the subdomain or set an environment variable in your .htaccess file so you can tell which subdomain you are in.