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

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;

Related

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;

Codeigniter mysql sum query

$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');

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?

zend router optimization

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

How do I write chains of chains of ... of route in a ini file for the Zend framework?

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"