I am trying to setup ZfcUser as described in README.md on the github page.
I understand all but this step in Post-Install: Zend\Db;
2. Now, specify the DI alias for your PDO connection in ./configs/autoload/module.zfcuser.config.php, under the 'pdo' setting. If you created the ./config/autoload/database.config.php file in the previous step, the alias you'll specify is 'masterdb'.
Can anyone describe me what exactly to do?
Thanks very much.
Manage to fix this by updating the parameter name in module.config.php for ZfcUser. Corrected from
'zfcuser_user_tg' => array(
'parameters' => array(
'table' => 'user',
'adapter' => 'zfcuser_zend_db_adapter',
),
),
'zfcuser_usermeta_tg' => array(
'parameters' => array(
'table' => 'user_meta',
'adapter' => 'zfcuser_zend_db_adapter',
),
),
to
'zfcuser_user_tg' => array(
'parameters' => array(
'tableName' => 'user',
'adapter' => 'zfcuser_zend_db_adapter',
),
),
'zfcuser_usermeta_tg' => array(
'parameters' => array(
'tableName' => 'user_meta',
'adapter' => 'zfcuser_zend_db_adapter',
),
),
table => corrected to tableName
I had the same problem. The solution was to uncomment line 15 in module.zfcuser.config.php and not use the 'masterdb' ...
'zend_db_adapter' => 'Zend\Db\Adapter\Adapter',
See support issue ...
https://github.com/ZF-Commons/ZfcUser/issues/42
Related
I have strange behavior with database custom factory.
For example I want to use BjyProfiler and create 1 config like this:
'db' => array(
'driver' => 'Pdo',
'dsn' => 'mysql:dbname=framework;host=localhost',
'username' => 'root',
'password' => '',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Database\Adapter\MainAdapterFactory',
),
),
So to use Zend\Db I added the module in modules.config.php "Zend\Db"(otherwise I get exceptions). The problem is that when I want to get "Zend\Db\Adapter\Adapter", it never go through "Database\Adapter\MainAdapterFactory" and I don't know why... It use some default Adapter. I triend to put factory declaration in global.php, local.php and it doesn't work. Why is this happening? In zf2 this code is ok...
I use composer if that matters.
Update: In my final config I have:
'service_manager' =>
array (size=5)
'aliases' =>
array (size=11)
...
'Zend\Db\Adapter\Adapter' => string 'Zend\Db\Adapter\AdapterInterface' (length=32)
...
'factories' =>
array (size=19)
...
'Zend\Db\Adapter\AdapterInterface' => string 'Zend\Db\Adapter\AdapterServiceFactory' (length=37)
...
'Zend\Db\Adapter\Adapter' => string 'Database\Adapter\Factory\MainAdapterFactory' (length=43)
'abstract_factories' =>
array (size=3)
...
1 => string 'Zend\Db\Adapter\AdapterAbstractServiceFactory' (length=45)
...
...
I don't know from where it comes alias 'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterInterface' but I think this is the problem.
The 'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterInterface' come from the framework.
I suggested you to extends the original 'Zend\Db\Adapter\Adapter' with your own adapter (let's call it MyAdapter), and use your custom adapter:
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\MyAdapter' => 'Database\Adapter\MainAdapterFactory',
),
),
I'm working with zend framework 2 and I need to create an optional parameter for a route segment that also has two required parameters. Below is a snippet from the module.config.php describing the route. My understanding is that in ZF2 an optional route parameter can be created by using the
[/:param]
which you can see is what I have. It works fine as long as I send the optional param, but when I leave it out the first two params "uname and appname" are appended together into the "uname" constraint. The route is a parent route.
'roles' => array(
'type' => 'segment',
'options' => array(
'route' => '/roles/:uname/:appname[/:locnames]',
'constraints' => array(
'uname' => '[a-zA-Z].+',
'appname' => '[a-zA-Z0-9_-].+',
'locnames' => 'locnames'
),
'defaults' => array(
'controller' => 'Roles/Controller/RolesController'
),
),
),
What am I missing here, I know you can have define optional parameters, but I can't figure out the correct format
Thanks to grizzm0 on #zftalk or helping me with this one. It was a simple regular expressions issue. Removing the dot(.) in the constraints correctly matched the incoming url parameters. So my route now looks like this:
'roles' => array(
'type' => 'segment',
'options' => array(
'route' => '/roles[/:action][/uname/:uname][/appname/:appname][/locnames/:locnames]',
'constraints' => array(
'uname' => '[a-zA-Z]+',
'appname' => '[a-zA-Z0-9_-]+',
'locnames' => 'locnames'
),
'defaults' => array(
'controller' => 'Roles/Controller/RolesController'
),
),
),
'roles' => array(
'type' => 'segment',
'options' => array(
'route' => '/roles[/:action][/uname/:uname][/appname/:appname][/locnames/:locnames]',
'constraints' => array(
'uname' => '[a-zA-Z].+',
'appname' => '[a-zA-Z0-9_-].+',
'locnames' => 'locnames'
),
'defaults' => array(
'controller' => 'Roles/Controller/RolesController'
),
),
),
You can configure your route like this way.
Here inside your roles controller
you have some action live index.
so your route will be
siteurl/roles/index/uname/john/appname/stackexchange/locanames/yourlocanames
here if you don't want to write appname then remove youre paramater so your route will work.
I follow this tutorial: http://ivangospodinow.com/zend-framework-2-acl-setup-in-5-minutes-tutorial/
But, I want to grant permission by custom URLs, so I had some changes in my code.
In module.acl.roles.php
return array(
'guest'=> array(
'/home.html',
'/login.html',
'/register.html'
),
'admin'=> array(
'/user/add.html',
'/user/edit.html',
'/user/list.html',
),
);
In module.config.php
return array(
'router' => array(
'routes' => array(
'/home.html' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
'/user/add.html' => array(
'type' => 'Zend\Mvc\Router\Http\Regex',
'options' => array(
'regex' => '/user/add.html',
'defaults' => array(
'controller' => 'Application\Controller\User',
'action' => 'add',
'format' => 'html',
),
'spec' => '/user/add.%format%',
),
),
...
),
),
);
But I received this error: Route with name "" not found. Please give me some advices and solutions to grant permission by URLs
Thank you!
I really really recommend the BjyAuthorize module (https://packagist.org/packages/bjyoungblood/bjy-authorize).
But if you really want to do this by yourselft you need to add a listener to the \Zend\Mvc\MvcEvent::EVENT_ROUTE.
You can attach your listener with
$events->attach(MvcEvent::EVENT_ROUTE, array($this, 'myOnRoute'), -1000);
and in your myOnRoute method you can handle the route
public function myOnRoute(MvcEvent $event) {
$match = $event->getRouteMatch();
$routeName = $match->getMatchedRouteName();
// do stuff here (compare to config or whatever)
}
I am trying to solve the routing problem I am facing right now with no luck (googled for hours, saw dozens of examples and solved questions but none works for me - the closest one is this Routing Zend Framework 2 Language in url but even this is not working for me).
I have created an SSO application (I mean the authentication part) and now I am porting it to ZF2 app (I have it almost working as I workarounded the router but need now the final routing to be done) where only these types of URLs are possible:
http[s]://domain.com/login/asfgsdgdsfgzsdgdsf/
http[s]://domain.com/login/tdhjsdgbndfnfgdnhd/
http[s]://domain.com/logout/asfgsdgdsfgzsdgdsf/
http[s]://domain.com/info/dthnzdfbdfhgnfsd/
Those login, logout or info parts are not the controllers nor actions but the methods names I then call on SSO service from within my IndexController and indexAction(). The rest part of the URL is the client application hash.
Now here is my router config which only matches the home route and when the other parts (method name [and hash]) are provided, I got 404 from the ZF2 app (so at least I am in the app context).
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'SSO\Controller\Index',
'action' => 'index',
'act' => 'login', // by doing this I am able to workaround the router and work with SSO
'client' => '<my_secret_hash>', // by doing this I am able to workaround the router and work with SSO
),
),
'child_routes' => array(
'action' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '[/:act]',
'defaults' => array(
'act' => 'login',
),
'constraints' => array(
'act' => '(login|logout|info)?', // only login, logout or info are allowed
),
),
'child_routes' => array(
'client' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '[/:client]',
'constraints' => array(
'client' => '[a-zA-Z0-9]+',
),
'defaults' => array(
'client' => '<my_secret_hash>',
),
'may_terminate' => true,
),
),
),
),
),
),
),
);
(only router part of my module.config is provided...)
Now with that router only http[s]://domain.com[/] is matched and either of http[s]://domain.com/(login|logout|info)[/] or http[s]://domain.com/(login|logout|info)/adfbsDVdfbzdbxfbndzxbxfnb[/] matches into A 404 error occured.
Though I try to define the route parts as optional (just for the testing and development purposes), they should by required in the production environment. Anyway, I tried to define them NOT optional too, but didn't work either.
Question: How should I configure the router to match my routes (URLs) defined in the beginning?
Couple of things:
My guess is that you have too many slashes in there -- a child route of / doesn't need to be defined with a slash at the beginning since it's parent already got it
I don't see a reason for 2 nested routes (of course I don't know the rest of your config, so it's a guess)
home route probably should be Literal and able to terminate (again a guess)
there was one unmatched parenthesis (probably 'misspasted' or something)
I suppose this should work for you:
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Literal',
'may_terminate' => true,
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'SSO\Controller\Index',
'action' => 'index',
),
),
'child_routes' => array(
'whateva' => array(
'type' => 'Segment',
'may_terminate' => true,
'options' => array(
'route' => '[:act[/:client]]', // as Sam suggested
'defaults' => array(
'act' => 'login',
'client' => 'fsadfasf32454g43g43543',
),
'constraints' => array(
'act' => '(login|logout|info)',
'client' => '[a-zA-Z0-9]+',
),
),
),
),
),
),
),
Running into a bit of a hurdle, and I can't find any supporting documentation. My use case is fairly simple. The Application module has javascript that should go into the head, and one of my other modules, Foo also has script that should go into the head. I assumed that this Assetic module could solve that. Here's what I inferred:
Application Config
/**
* Assetic
*/
'assetic_configuration' => array(
'buildOnRequest' => true,
'cacheEnabled' => false,
'webPath' => realpath('public/assets'),
'basePath' => 'assets',
'default' => array(
'assets' => array(
'#base_css',
'#head_js',
),
'options' => array(
'mixin' => true,
),
),
'modules' => array(
'application' => array(
# module root path for yout css and js files
'root_path' => __DIR__ . '/../assets',
# collection of assets
'collections' => array(
'base_css' => array(
'assets' => array(
'css/*.css',
),
'filters' => array(),
'options' => array(),
),
'head_js' => array(
'assets' => array(
'js/*.js',
),
'filters' => array(),
),
'base_images' => array(
'assets'=> array(
'images/*.png',
),
'options' => array(
'move_raw' => true,
)
),
),
),
),
),
and then in my Foo module...
Foo Module config
/**
* Assetic
*/
'assetic_configuration' => array(
'default' => array(
'assets' => array(
'#base_css',
'#head_js',
),
'options' => array(
'mixin' => true,
),
),
'modules' => array(
'foo' => array(
# module root path for yout css and js files
'root_path' => __DIR__ . '/../assets',
# collection of assets
'collections' => array(
'base_css' => array(
'assets' => array(
'css/*.css'
),
'filters' => array(),
'options' => array(),
),
'head_js' => array(
'assets' => array(
'js/*.js' // relative to 'root_path'
),
'filters' => array(),
'options' => array(),
),
'base_images' => array(
'assets'=> array(
'images/*.png'
),
'options' => array(
'move_raw' => true,
)
),
),
),
),
),
With this config, unfortunately, only the Foo module's javascript makes its way into head_js.js. I'm feeling like that meme with Milton in it, going "I was told there would be asset combining!" :)
Any help you could offer, is appreciated.
Thanks!
Ok - I've figured it out. Hopefully this helps someone else one day. The configuration keys I noted above weren't inaccurate -- but -- they weren't crafted properly when a secret undocumented feature is considered; had to crack the source open to learn that including the word 'head' in an asset bundle actually autoloads it in the head. It's a nice feature in the end, but really a head scratcher when you're not aware of it.