How to use extensions in Zend Framework Routing - zend-framework

I'd like to use an extension like .htm in my URLs. Is there a way to accomplish that?
I've defined the following rule:
frontend.route = '/:standort/:id'
When I use the following
frontend.route = '/:standort/:id.htm'
then the name of the variable is id.htm like in $params["id.htm"].
How can I tell the Zend Framework what to use as variables?
Greetings
//Edit
my full config looks like this now:
frontend.type = 'Zend_Controller_Router_Route_Regex'
frontend.route = '/(.?)/(\w+?\.htm)'
frontend.defaults.module = 'frontend'
frontend.defaults.controller = 'index'
frontend.defaults.action = 'index'
frontend.defaults.standort = 'national'
frontend.map.1 = 'standort'
frontend.map.2 = 'id'
this is how I load the config
$file = APPLICATION_PATH . '/modules/' . $module . '/configs/routing.ini';
if(Zend_Loader::isReadable($file)){
$config = new Zend_Config_Ini($file);
$router = Zend_Controller_Front::getInstance()->getRouter();
$router->addConfig($config);
}

You can do this with regex routes:
frontend.type = "Zend_Controller_Router_Route_Regex"
frontend.route = '/(.?)/(\w+?\.htm)'
frontend.map.1 = "standort"
frontend.map.2 = "id"
but unless you're trying to preserve an existing URL structure, I'd just leave the .htm out - it serves no purpose.

Related

how to use insert record function in moodle

I am trying to insert record into my database using moodle.
I am using version 1.9.19. i am trying the following code :
<?php
require_once('config.php');
require_once('uplo.php');
$mform = new uplo();
$mform->display();
if(isset($_POST['submitbutton'])){
$name = $mform->get_data('name');
$email = $mform->get_data('email');
$table='mdl_tet';
$res=insert_record($table, '$name','$email') ;
}
?>
But this is not working correctly. How to do that correctly.
Note : Why am using 1.9.19 means my client using this version so i cant change the version.
The insert_record() function takes two parameters - the name of the table (without the prefix) and an object containing the data to insert into the table.
So, in this case, you should write something like:
$ins = (object)array('name' => $name, 'email' => $email);
$ins->id = insert_record('tet', $ins);
OR:
$ins = new stdClass();
$ins->name = $name;
$ins->email = $email;
$ins->id = insert_record('tet', $ins);
(As an aside - make sure you turn on debugging - https://docs.moodle.org/19/en/Debugging - it will make your life a lot easier).

zfdatagrid - Plugin by name 'Table' was not found in the registry;

I've just installed the library and tried a simple table with an array
$grid = Bvb_Grid::factory("Bvb_Grid_Deploy_Table");
$grid->setSource(new Bvb_Grid_Source_Array($this->pkg));
$myGrid = $grid->deploy();
I get this error:
Plugin by name 'Table' was not found in the registry; used paths: Bvb_Grid_Template_: Bvb/Grid/Template/
I'm not familiar with how this works, but would guess looking at the error that it looks in the Bvb/Grid/Template/ directory, there is a Table.php in there with the class Bvb_Grid_Template_Table.Thank you.
Try a little bit different. Write "Table" instead of "Bvb_Grid_Deploy_Table". In my example there is also grid configuration file...
$config = new Zend_Config_Ini(dirname(__FILE__) . '/../configs/grid.ini','clients');
$grid = Bvb_Grid::factory('Table', $config);
$model = new Sand_Model_DbTable_Asset();
$source = new Bvb_Grid_Source_Zend_Table($model);
$grid->setSource($source);
/*
more code here...
*/
$myGrid = $grid->deploy();
$this->view->grid = $myGrid;

Zend redirector and module as subdomain

I have configured route for cms in my project to cms.m.dev
resources.router.routes.cms.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.cms.route = "m.dev"
resources.router.routes.cms.defaults.module = "cms"
resources.router.routes.cms.chains.admin_default.route = "/:controller/:action/*"
resources.router.routes.cms.chains.admin_default.defaults.action = "index"
resources.router.routes.cms.chains.admin_default.defaults.controller = "dashboard"
but now I have problem with redirector:
$this->_redirector->gotoUrl('/doctor/edit/');
$this->_redirector->gotoSimple('edit', 'doctor', 'cms');
When I call it like this it redirects me to to m.dev/cms/doctor/edit instead of cms.m.dev/doctor/edit . Is there any way I can tell redirector that module is subdomain, not subdirectory?
UPDATE: I have created route:
resources.router.routes.cms_doctor_index.route = "/doctor/"
resources.router.routes.cms_doctor_index.type = "Zend_Controller_Router_Route_Static"
resources.router.routes.cms_doctor_index.defaults.module = "cms"
resources.router.routes.cms_doctor_index.defaults.controller = "doctor"
resources.router.routes.cms_doctor_index.defaults.action = "index"
But it still redirects me to m.dev/doctor/
You should try gotoRoute() to specify that you want the redirector to use your special route
gotoRoute (
array $urlOptions = array(),
$name = null, // $name = "m.dev"
$reset = false,
$encode = true
)
I haven't tested this, but it should work.

Module based application.ini in Zend Framework

I want to have module based application.ini in my application.
Is it possible?
Basic requirement arises because I am having multiple databases depending on modules.
Please guide.
You can use multiple Db in application.ini:
resources.db.master.adapter = "PDO_MYSQL"
resources.db.master.default = false
resources.db.master.params.dbname = "db1"
resources.db.master.params.host = "127.0.0.1"
resources.db.master.params.username = "root"
resources.db.master.params.password = ""
resources.db.slave.adapter = "PDO_MYSQL"
resources.db.slave.default = true
resources.db.slave.params.dbname = "db2"
resources.db.slave.params.host = "127.0.0.1"
resources.db.slave.params.username = "root"
resources.db.slave.params.password = ""
And initialize in your bootstrap:
public function _initDatabase() {
$config = $this->getApplication()->getOption('resources');
$dbArrays = array();
foreach($config['db'] as $name => $dbConf){
// Set up database
$db = Zend_Db::factory($dbConf['adapter'], $dbConf['params']);
$db->query("SET NAMES 'utf8'");
$dbArrays[$name] = $db;
if((boolean)$dbConf['default']){
Zend_Db_Table::setDefaultAdapter($db);
}
unset($db);
}
Zend_Registry::set("db", $dbArrays);
}
In my case I always save each adapter in the registry so I can use them separately later.
I also made a new class which extend Zend_Db_table where I have My own getAdapter($name) like so:
public function getAdapter($name = null){
if($name !== null){
$dbAdapters = Zend_Registry::get('db');
return $dbAdapters[$name];
}
return parent::getAdapter();
}
With that in each model I can do:
$this->getAdapter('slave')->fecthAll($sql);
$this->getAdapter('master')->fecthAll($sql);
The application.ini is read long before the module is determined. I'd suggest you forget about application.ini and instead try and write a controller plugin that will load in some additional configuration depending on which module was selected.

Zend_Translate, set up the log via the application resource plugin?

I'm using application resource plugins in a .ini file to set up my Zend_Translate with this code:
resources.translate.data = APPLICATION_PATH "/../languages"
resources.translate.adapter = "gettext"
resources.translate.options.scan = "directory"
Now I would like to add the log functionality to the translate, which in bootstrap I would do like this:
$writer = new Zend_Log_Writer_Stream( APPLICATION_PATH . '/../logs/translate.log');
$log = new Zend_Log($writer);
$translate->setOptions(
array(
'log' => $log,
'logUntranslated' => true
)
);
2 questions about this:
First, is it possible to this in the .ini file?
Secondly, it is possible to "extend" resource settings in the bootstrap? In other words, could I add for example this log option in the bootstrap to the translate while maintaining the other settings already made in the .ini file?
Alright, I haven't found a solution to this in the ini file, but I have found a way to "extend" my settings from the ini file in the bootstrap without overwriting them. I managed to do that like this:
protected function _initTranslate()
{
$writer = new Zend_Log_Writer_Stream( APPLICATION_PATH . '/../somedir/somefile.log');
$log = new Zend_Log($writer);
// get the translate resource from the ini file and fire it up
$resource = $this->getPluginResource('translate');
$translate = $resource->getTranslate();
// add the log to the translate
$translate->setOptions(
array(
'log' => $log,
'logUntranslated' => true
)
);
// return the translate to get it in the registry and so on
return $translate;
}
This works just fine. I'm going to remove the translate from the .ini though because I'm switching to my own adapter and don't know (yet) how to pull that off from the ini.