How to make parameter optional in Zend Framework Router - regex

I would like to know the .ini config file setup to make a route wherein the page number parameter is optional so that
http://news.mysite.com/national
http://news.mysite.com/national/1
point to the same page.
I have the code as follows
resources.router.routes.news_list.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.news_list.route = "([a-zA-Z0-9\-]+)/([0-9\-]+)"
resources.router.routes.news_list.defaults.module = "news"
resources.router.routes.news_list.defaults.controller = "index"
resources.router.routes.news_list.defaults.action = "category"
resources.router.routes.news_list.defaults.page = 1
resources.router.routes.news_list.map.1 = "categ"
resources.router.routes.news_list.map.2 = "page"
resources.router.routes.news_list.reverse = "%s/%s"
can some1 help me out with a solution to modify this code to make it work for both urls

You can do this without the regex route using:
routes.news_list.route = ":action/:page"
routes.news_list.defaults.module = "news"
routes.news_list.defaults.controller = "index"
routes.news_list.defaults.action = "category"
routes.news_list.defaults.page = 1
I assume that you want every request to go to the "news" module and the "index" controller. Only the action and the page are variable in the url.

resources.router.routes.news_list.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.news_list.route = "([a-zA-Z0-9-]+)/?([0-9]+)?"
resources.router.routes.news_list.defaults.module = "news"
resources.router.routes.news_list.defaults.controller = "index"
resources.router.routes.news_list.defaults.action = "category"
resources.router.routes.news_list.defaults.page = 1
resources.router.routes.news_list.map.1 = "categ"
resources.router.routes.news_list.map.2 = "page"
resources.router.routes.news_list.reverse = "%s/%d"
Something like this could work too in case you need to use Regex.

Related

Generating a data table to iterate through in a Django Template

I have this function that uses PrettyTables to gather information about the Virtual Machines owned by a user. Right now, it only shows information and it works well. I have a new idea where I want to add a button to a new column which allows the user to reboot the virutal machine. I already know how to restart the virtual machines but what I'm struggling to figure out is the best way to create a dataset which i can iterate through and then create a HTML table. I've done similar stuff with PHP/SQL in the past and it was straight forward. I don't think I can iterate through PrettyTables so I'm wondering what is my best option? Pretty tables does a very good job of making it simple to create the table (as you can see below). I'm hoping to use another method, but also keep it very simple. Basically, making it relational and easy to iterate through. Any other suggestions are welcome. Thanks!
Here is my current code:
x = PrettyTable()
x.field_names = ["VM Name", "OS", "IP", "Power State"]
for uuid in virtual_machines:
vm = search_index.FindByUuid(None, uuid, True, False)
if vm.summary.guest.ipAddress == None:
ip = "Unavailable"
else:
ip = vm.summary.guest.ipAddress
if vm.summary.runtime.powerState == "poweredOff":
power_state = "OFF"
else:
power_state = "ON"
if vm.summary.guest.guestFullName == None:
os = "Unavailable"
else:
os = vm.summary.guest.guestFullName
x.add_row([vm.summary.config.name, os, ip, power_state])
table = x.get_html_string(attributes = {"class":"table table-striped"})
return table
Here is a sample of what it looks like and also what I plan to do with the button. http://prntscr.com/nki3ci
Figured out how to query the prettytable. It was a minor addition without having to redo it all.
html = '<table class="table"><tr><th>VM Name</th><th>OS</th><th>IP</th><th>Power
State</th></tr>'
htmlend = '</tr></table>'
body = ''
for vmm in x:
vmm.border = False
vmm.header = False
vm_name = (vmm.get_string(fields=["VM Name"]))
operating_system = (vmm.get_string(fields=["OS"]))
ip_addr = ((vmm.get_string(fields=["IP"])))
body += '<tr><td>'+ vm_name + '</td><td>' + operating_system + '</td> <td>'+ ip_addr +'</td> <td>ON</td></tr>'
html += body
html += htmlend
print(html)

Adding custom dropdown(values dynamically from db) in the lead form in vTiger

I am new to vtiger crm and need a code to add the dropdown that has values from the database table in add lead page.
Please provide a solution if somebody have ?
You can add drop-down field by using bellow code and follow the steps to achieve your result:
Add bellow code in one PHP file (e.g add_to_lead.php).
Put that file into your project directory.
Run that file from browser (e.g www.yourVtigerhost.com/add_to_lead.php)
$Vtiger_Utils_Log = true;
include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/Module.php');
$module = new Vtiger_Module();
$module = $module->getInstance('Leads');
// Create new Block into Lead Module and your drop-down added into new block
$block1 = new Vtiger_Block();
$block1->label = 'LBL_LEAD_INFORMATION';
$block1 = $block1->getInstance($block1->label,$module);
$field0 = new Vtiger_Field();
$field0->name = 'your field name';
$field0->table = $module->basetable;
$field0->label = 'Your field Name to display';
$field0->column = 'field_name';
$field0->columntype = 'VARCHAR(100)';
$field0->uitype = 15;
$field0->setPicklistValues( Array ('Dropdown Value1','Dropdown Value2','Dropdown Value3'));
$field0->typeofdata = 'V~O';
$block1->addField($field0);
New Dropdown have values like Dropdown Value1,Dropdown Value2,Dropdown Value3
If you want to add more values into dropdown than you can add from Setting-> Studio->Picklist Editor.

if self.request.GET[key] fetch value of key?

I'm trying to get the value of a key in the URL (localhost:8080?color=red) and display different pages according to what value is in the url (red or blue...etc). I'm not sure how to set that up, though, because nothing I've tried works. Any ideas? It's for a class assignment, so I can't use query_string.
if self.request.GET(['color','red']):
view = ContentPage()
fetch_data = Data()
name = fetch_data.red.name
description = fetch_data.red.description
self.response.write(view.print_first() + name + description + view.print_end())
else:
see = Page()
self.response.write(see.output())
Use self.request.get, like this:
color = self.request.get('color')
# do something with color

Zend Framework : How to handle "No route matched the request" error?

In Bootstrap.php I have some custom routes using Zend_Controller_Router_Route_Regex.
Everything works fine except when user type in address bar a wrong link.
Ex :
http://mysite/en/1-some-article.html => This is a valid link that matches a ROUTE in Bootstrap.
But when user make a typo mistake like:
http://mysite/en/1-some-article.**html'** or http://mysite/en/1-some-article.**hhtml** , they are not match any ROUTE in Bootstrap, then Zend Framework throws an exception like : No route matched the request
Is there anyway to handle it, like redirecting to a custom page for "No matched routes"?
Any help will be appreciated. Thanks for advance!
Configuration (from comment below)
[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
phpSettings.date.timezone = "Europe/London"
;includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = ""
;resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules = ""
autoloaderNamespaces.Fxml = "Mycms_"
autoloaderNamespaces.Fxml = "Fxml_"
To make use of the ErrorController, you need to set the front controller throwExceptions attribute to false. Put this in your [production] configuration section
resources.frontController.params.throwExceptions = 0
See http://framework.zend.com/manual/1.12/en/zend.controller.exceptions.html and http://framework.zend.com/manual/1.12/en/zend.controller.plugins.html#zend.controller.plugins.standard.errorhandler.fourohfour.
I mentioned this in the comments above but you seem to have missed it (you have displayExceptions set to false but not throwExceptions).

Zend_Controller_Router_Route_Regex not matching latin, but only cyrillic characters

I have defined the following custom routes:
; Language
routes.lang.type = "Zend_Controller_Router_Route"
routes.lang.route = :lang
routes.lang.defaults.lang = "bg"
routes.lang.defaults.action = "index"
routes.lang.defaults.controller = "index"
routes.lang.defaults.module = "site"
routes.lang.reqs.lang = "[a-z]{2}"
; Article
routes.lang.chains.a.type = "Zend_Controller_Router_Route_Regex"
routes.lang.chains.a.route = "([^\.html ]+).html$"
routes.lang.chains.a.defaults.action = "index"
routes.lang.chains.a.defaults.controller = "article"
routes.lang.chains.a.defaults.module = "site"
routes.lang.chains.a.map.articleIdent = 1
routes.lang.chains.a.reverse = "%s.html"
When I try to access the following url, everything works fine:
http://site.local/en/ั‚ะตัั‚.html -> match
The problem is that when I try to access the url containing only latin characters, the route is being passed:
http://site.local/en/test.html -> not match
I just can't figure it out where is the problem. Any help is greatly appreciated!
The problem was in the regular expression. In the round brackets I wanted to include everything except ".html", but the syntax is wrong. Well I still don't now that should be the right syntax, but anyway the following change got the job done:
routes.lang.chains.a.route = "(.*).html$"