ZfcUserDoctrineMongoODM Configuration examples - mongodb

I am trying to configure ZendFramwork 2 to use MongoDB as the storage for user Authentication.
I already have installed what I believe are the correct modules and have a correctly installed instance of ZF2 running on Nginx. I also have an instance of Mongo running and I am already using this for another project. The modules declaration in application.config.php looks like this
'modules' => array(
'Application',
'ZfcBase',
'ZfcUser',
'ZfcUserDoctrineMongoODM',
'DoctrineModule',
'DoctrineMongoODMModule'
)
Documentation is a bit thin on how to configure the system to get it working. Can anyone provide any code fragments around configuring the database settings to allow Mongo to run with ZfcUser, this is where I am at a loss now.
Any help, clues or cheat sheets would be greatly appreciated.
Darren Breeze

Have a look at Doctrine Mongo ODM module readme https://github.com/doctrine/DoctrineMongoODMModule :
copy
vendor/doctrine/doctrine-mongo-odm-module/config/module.doctrine-mongo-odm.local.php.dist
into your application's config/autoload directory, rename it to
module.doctrine-mongo-odm.local.php and make the appropriate changes.
With this config file you can configure your mongo connection, add
extra annotations to register, add subscribers to the event manager,
add filters to the filter collection, and drivers to the driver chain.
So you have something like this at your autoload config:
<?php
return array(
'doctrine' => array(
'connection' => array(
'odm_default' => array(
'server' => 'localhost',
'port' => '27017',
// 'connectionString' => null,
// 'user' => null,
// 'password' => null,
// 'dbname' => null,
// 'options' => array()
),
),
....
'configuration' => array(
'odm_default' => array(
... 'default_db' => 'myappdb',
)
)
So tune it and try to register at user/register. Collection name is user by default.

Related

how to access local.php file from controller in zf3

I am working with Zend-framework 3. I want to access the content of config files (local.php) in the controller. please explain. Thank you all in advance.
After some research, I found the simplest way to access any config file. Just in your Module.php pass $container->get('config') as one of the argument to your controller's constructor and voila you can now access any property in the controller. That much simple. :-) Happy coding..!!
You can do something like this (it's not tested):
// config.php
return [
'webhost' => 'www.example.com',
'database' => [
'adapter' => 'pdo_mysql',
'params' => [
'host' => 'db.example.com',
'username' => 'dbuser',
'password' => 'secret',
'dbname' => 'mydatabase',
],
],
];
And in your controller:
// Consumes the configuration array
$config = new Zend\Config\Config(include 'config.php');
// Print a configuration datum (results in 'www.example.com')
echo $config->webhost;
Presume, you have this ZF3 package: zend-config
If you dont have, you have to include it via composer
composer require zendframework/zend-config

How to add custom wizards in typo3 7 TCA?

When I try to add the wizard named wizard_geo_selector in TCA ,there arised an error "module not registered".Please tell me how to register the wizard properly in the TCA.?
In TYPO3 Version 7.6 new wizards are added like this:
Inside your extension create the directory Configuration/Backend/
In the new directory create a file Routes.php, it will be found automatically, no mentioning in ext_localconf.php or ext_tables.php is required. If you still need Ajax you can add the file AjaxRoutes.php in the same folder.
Content for Routes.php:
return array(
'my_wizard_element' => array(
'path' => '/wizard/tx_geoselecotor/geo_selector_wizard',
'target' => \Path\To\your\class\WizardGeoSelector::class . '::WizardAction'
),
);
Content for AjaxRoutes.php
<?php
/**
* Definitions for routes provided by EXT:backend
* Contains all AJAX-based routes for entry points
*
* Currently the "access" property is only used so no token creation + validation is made
* but will be extended further.
*/
return array('my_ajax_element' => array(
'path' => 'tx_geoselecotor/my_ajax_route',
'target' => \Path\To\your\class\MyAjaxController::class .'::myAjaxFunction'
));
If you're unsure about the notation you can compare with existing entries in the Global Variables in the Backend:
Navigate to System -> Configuration -> Backend Routes
The route of the paths is handled different, for Ajax it's always "ajax" prepended, so you've never to add it to the path, else it's twice in the route. For the common route there is no change concerning the defined string.
Now the wizard can be used and even it never has to be defined in ext_tables.php it has to be mentioned there from any table-field in the configuration-area (module[name]):
'table_field_for_wizard' => array(
'label' => 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xml:table_name.tx_myextension_wizard',
'config' => array (
'type' => 'user',
'userFunc' => 'Path/to/class/without/wizard->renderForm',
'wizards' => array(
'my_wizard' => array(
'type' => 'popup',
'title' => 'MyTitle',
'JSopenParams' => 'height=700,width=780,status=0,menubar=0,scrollbars=1',
'icon' => 'EXT:' . $_EXTKEY . '/Resources/Public/img/link_popup.gif',
'module' => array(
'name' => 'my_wizard_element',
'urlParameters' => array(
'mode' => 'wizard',
'ajax' => '0',
'any' => '... parameters you need'
),
),
),
'_VALIGN' => 'middle',
'_PADDING' => '4',
),
# Optional
#'softref'=>'something',
),
),
In the userFunc Path/to/class/without/wizard->renderForm you've to create a button which is linking to the wizard and onClick the wizard will open with the route you defined in Routes.php and the optional urlParameters.
Currently I never found this whole item explained in the core-documentation.
Edit:
Details about routing can be found here: Routing
The rendering process can be found here: Rendering / NodeFactory
You should probably read also the outer context of the linked paragraph.
Edit 2:
An example extension can be found here, some things never work 100% but the wizard is working. The extension is for TYPO3 Version 7:
https://github.com/DavidBruchmann/imagemap_wizard
Ricky's answer doesn't really work anymore, since addModulePath ist deprecated since version 7.
Also, just registering the module like this still give's you said error.
The only thing that keeps the wizard going again is this:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModule('wizard','pbsurvey_answers',"",\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY).'wizard/');
But when you add this, the module appears as a new point in your TYPO3 backend.
IN TCA add the wizard like follows:
'module' => array(
'name' => 'wizard_geo_selector',
),
In ext_tables.php register the wizard.
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModulePath(
'wizard_geo_selector',
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'Modules/Wizards/Yourwizardname/'
);
Keep in mind this is deprecated since Typo3 7 and removed in Typo3 8.So you can use this method upto Typo3 7.For Typo3 8 do use the method specified by David below.

how to change default module in Zend 2

I am new to ZendFeamerwork version 2. I could easily change the default controller in Zend1 but it seems very difficult to me to find out how to change default module in Zend2.
I searched over google but there is no easy solution.
I just created a module named "CsnUser" I can access this module via the following url
http://localhost/zcrud/public/csn-user/
I want csn-user to load instead of "application" module i.e url should be
http://localhost/zcrud/public/
or
http://localhost/zcrud/
Please let me know how to get this done.
Based on #Hoolis comment:
You have to set that action on this route
'home' => array(
'type' => 'Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'That\Namespace\CsnUser',
'action' => 'index'
)
)
)
)
In the skeleton application this route is set in the Application Module, but you can move this somewhere or edit it.

Zf2 + Doctrine 2 Authentication Adapter with Multiple or Alternate Columns

I am working on a site in which user can enter two email address(primary and secondary) along with password.
If user enters his primary email and password, he gets logged in successfully.
But, what I am trying to provide is if user enters his secondary email instead of primary, even then he gets logged in. And the problem I am getting is how to create an alternate Doctrine Auth Adapter or something like that.
this is what I have done in my module.config.php:
'doctrine' => array(
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
)
)
),
'authentication' => array(
'orm_default' => array(
'object_manager' => 'Doctrine\ORM\EntityManager',
'identity_class' => 'User\Entity\LoginDetails',
'identity_property' => 'primary_email',
'credential_property' => 'password',
),
),
)
Is there any option to add an identity property which will be alternative ?
I am using Zend framework 2 and Doctrine 2
Is there any option to add an identity property which will be alternative ?
No, there is no such option built-in to DoctrineModule.
Consider extending DoctrineModule\Authentication\Adapter\ObjectRepository to override the authenticate() method.
Then, at minimum, you'll want to replace the default adapter with your new more different one. If you look at the various factories in DoctrineModule, you should be off to a good start.
Basically, one of your modules will want to override the doctrine.authenticationadapter.[orm|odm]_default configuration key in the ServiceManager. That will cause DoctrineModule to inject your extended ObjectRepository into the AuthenticationService in place of you the default one.

How to set table schema at table name with Cake?

PostgreSQL, Oracle and many other DBMS's use SCHEMA, so, the table name is
schema_name.table_name
But CakePHP manuals not say anithing about this. What about Model, View and Controller names in the CakePHP defaults? I can use a solution like prefix, that is, where the same schema name will be used at all database operations.
PS1: please not to be confused with method Modelschema, and questions about accessing this method.
PS2: the Bill's 2006 solution is not the better one, because is not updated (I am using CakePHP2) and is not a "official cakePHP solution".
PS3: database.php have some schema attribute? What the link to CakePHP documentation?
Good news for me, there are CakePHP 2.0 documentation about SQL-Schema... No other documentation or examples, but a starting point...
In CakePHP you must define more database config.
In CakePHP 2:
set the 'schema' param to your config
create new configs for all of your schema
use the right schema in your models
For example, database conf:
public $default = array(
'datasource' => 'Database/Postgres',
'persistent' => false,
'host' => 'localhost',
'login' => 'my_db_user',
'password' => 'my_db_passw',
'database' => 'my_project_db',
'prefix' => '',
'encoding' => 'utf8',
'schema' => 'postgres'
);
public $other_schema = array(
'datasource' => 'Database/Postgres',
'persistent' => false,
'host' => 'localhost',
'login' => 'my_db_user',
'password' => 'my_db_passw',
'database' => 'my_project_db',
'prefix' => '',
'encoding' => 'utf8',
'schema' => 'other_schema'
);
If you want to use it in a model:
class AppModel extends AppModel {
public $useDbConfig = 'other_schema';
}
In CakePHP3 is the same way, just there the database is config/app.php and you must use
use Cake\Datasource\ConnectionManager;
$connection = ConnectionManager::get('default');