zend router optimization - zend-framework

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).

Related

Crystal Lang convert string to hash and gsub

I have a string that looks like this
start
"contrib_11_FICO_Score = 0.7474262402579245 contrib_27_OtherPayments = -0.11397237107501418 contrib_20_LTV = 0.4209136780360599 contrib_0_AcctsOnUs = -0.195553721371136 contrib_19_InstallmentPayments = 0.08134999563389797 contrib_1_Amount = 0.07752028501333455 contrib_10_EstDebtToIncome = 0.19793275869285348 contrib_45_CVTE_ProductShortName.0 = 0.08545325753810393 contrib_21_LoanTerm = -0.20186524569828262 contrib_43_SatisfactoryLast2Yrs = 0.0710695727171011 contrib_50_WoE_ProductShortName.0 = -0.022073850549082376 contrib_31_PLCollectionTotal = 0.12617956675796796 contrib_40_RevBalToHighCredit = -0.5009070556076041 contrib_42_RevolvingPayments = 0.14787007118011708 contrib_39_RepoTotal = 0.002261663457841503 contrib_30_PLCollectionLast2yrs = 0.047241412208721086 contrib_15_InquiriesOnUs = -0.08118475273646548 contrib_17_InquiriesTotal = -0.23934745152247694 contrib_16_InquiriesToday = 0.06067597032236759 contrib_23_OilTE = -0.009115867521724635 contrib_14_InquiriesLast6mos = -0.01669536361883669 contrib_8_DTI = 0.40070958319864824 contrib_44_SatisfactoryTotal = -0.29471031930209096 contrib_22_Mortgage = -0.13973120155639737 contrib_3_AvgRevolvingBalance = -0.1339820646758586 contrib_41_RevolvingCount = 0.008316986809544236 contrib_32_Plus30Last2Yrs = 0.0315266336181764 contrib_29_OtherPublicTotal = 0.0025079738312499887 contrib_12_Inquiries30days = 0.08842218013671509 contrib_36_Plus90Last2Yrs = 0.03415210455083352 contrib_6_BankruptcyLast2yrs = 0.0037646391378712307 contrib_34_Plus60Last2Yrs = 0.014917255339436795 contrib_28_OtherPublicLast2yrs = 9.508765288605479E-4 contrib_bias = 0.7414680413223248"
and I'm trying to coerce it to a hash, like this.
end
{"contrib_11_FICO_Score"=>0.7474262402579245, "contrib_27_OtherPayments"=>-0.11397237107501418, "contrib_20_LTV"=>0.4209136780360599, "contrib_0_AcctsOnUs"=>-0.195553721371136, "contrib_19_InstallmentPayments"=>0.08134999563389797, "contrib_1_Amount"=>0.07752028501333455, "contrib_10_EstDebtToIncome"=>0.19793275869285348, "contrib_45_CVTE_ProductShortName"=>0.08545325753810393, "contrib_21_LoanTerm"=>-0.20186524569828262, "contrib_43_SatisfactoryLast2Yrs"=>0.0710695727171011, "contrib_50_WoE_ProductShortName"=>-0.022073850549082376, "contrib_31_PLCollectionTotal"=>0.12617956675796796, "contrib_40_RevBalToHighCredit"=>-0.5009070556076041, "contrib_42_RevolvingPayments"=>0.14787007118011708, "contrib_39_RepoTotal"=>0.002261663457841503, "contrib_30_PLCollectionLast2yrs"=>0.047241412208721086, "contrib_15_InquiriesOnUs"=>-0.08118475273646548, "contrib_17_InquiriesTotal"=>-0.23934745152247694, "contrib_16_InquiriesToday"=>0.06067597032236759, "contrib_23_OilTE"=>-0.009115867521724635, "contrib_14_InquiriesLast6mos"=>-0.01669536361883669, "contrib_8_DTI"=>0.40070958319864824, "contrib_44_SatisfactoryTotal"=>-0.29471031930209096, "contrib_22_Mortgage"=>-0.13973120155639737, "contrib_3_AvgRevolvingBalance"=>-0.1339820646758586, "contrib_41_RevolvingCount"=>0.008316986809544236, "contrib_32_Plus30Last2Yrs"=>0.0315266336181764, "contrib_29_OtherPublicTotal"=>0.0025079738312499887, "contrib_12_Inquiries30days"=>0.08842218013671509, "contrib_36_Plus90Last2Yrs"=>0.03415210455083352, "contrib_6_BankruptcyLast2yrs"=>0.0037646391378712307, "contrib_34_Plus60Last2Yrs"=>0.014917255339436795, "contrib_28_OtherPublicLast2yrs"=>9.508765288605479E-4, "contrib_bias"=>0.7414680413223248}
I can use gsub(" = ","=>")
.gsub(" contrib",","contrib").gsub("\","")
but I end up with
\"contrib
The backslashes prevent me from converting this to a hash. How can I strip the backslashes out? I would have thought that the escape character would work, but apparently not.
I also tried splitting the string on the space, but this gave me an array of strings and not a hash.
Thanks for any suggestions!

Codeigniter Pagination highlights last link when current link is first

I got a strange problem, Codeigniter Pagination highlights last link when current link is first
$route['favorite/(:num)'] = 'user/favorite/$1';
$route['favorite/(:num)/page/(:num)'] = 'user/favorite/$1/$2';
$this->load->library('pagination');
$config['base_url'] = "/favorite/$user_fav_id/page";
$config['total_rows'] = $this->user_model->count_user_fav_all_movies($user_id, $user_fav_id);
$config['per_page'] = 3;
$config['use_page_numbers'] = true;
$config['first_link'] = 'в начало';
$config['last_link'] = 'в конец';
$config['next_link'] = '';
$config['prev_link'] = '';
$config['first_url'] = "/favorite/$user_fav_id";
$this->pagination->initialize($config);
You have to tell CI at what page you are currently at, by providing uri_segment :
$config['uri_segment'] = $this->uri->total_segments();
Or
$config['uri_segment'] = 4;

zend route regex issue

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?

how to access the configuration data from within a controller action?

I have place this on my application.ini file:
contact.email.address = "my.mail#bla.org"
contact.email.name = "Test Name"
Then on my index controller action I have done:
$configOptions = $this->getInvokeArg('bootstrap')->getOptions();
$contactAddress = $configOptions->contact.email.address;
$this->view->contact = $contactAddress;
On my view I have:
var_dump($this->contact); but I'm receiving NULL.
What am I missing ?
In your controller, I think you want:
$configOptions = $this->getInvokeArg('bootstrap')->getOptions();
$contactAddress = $configOptions['contact']['email']['address'];
$this->view->contact = $contactAddress;
You can use:
$configOptions = new Zend_Config($this->getInvokeArg('bootstrap')->getOptions());
$contactAddress = $configOptions->contact.email.address;
$this->view->contact = $contactAddress;

Adding sub domain based routes in Zend framework

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.