BjyAuthorize settings file connect with database table - zend-framework2

I am using BjyAuthorize to control access in my project.
Everything working as expected with hard coded settings in module.bjyauthorize.global.php file. But my requirement is to set users dynamically and assign their user levels dynamically.
So I want to connect this file to DB tables some how and dynamically load settings. Please someone help me to get my thing done
Thank you

You have to create your own Providers or Guards that will load the settings from the database.
See BjyAuthorize\Provider\Role\ZendDb or BjyAuthorize\Provider\Role\ObjectRepositoryProvider.

You can set settings in the Module class.
use Zend\Mvc\MvcEvent;
class Module
{
public function onBootstrap(MvcEvent $event)
{
$serviceManager = $event->getApplication()->getServiceManager();
$authorizeService = $serviceManager->get('BjyAuthorize\Service\Authorize');
// settings
}
}

Related

Universal App Resource resw values in different views

I try to create a Universal Windows App which has a main window containing different views.
ContentFrame.Navigate(typeof(SimplePage));
where ContentFrame is a XAML Frame and SimplePage is a view.
The project has two localisations. Therefore I created a folder Strings in the solution containing two folders, en and de, containing each a Resources.resw file.
I want to use a string from the resw-file inside the SimplePage-view. Therefore I tried:
tbSimpleInput1.Text = ResourceManager.Current.MainResourceMap.GetValue("Resources/dataToolDiameter", ResourceContext.GetForCurrentView()).ValueAsString;
I also tried using ResourceContext.GetForViewIndependentUse() instead of ResourceContext.GetForCurrentView() but I always get a NullReferenceException when trying to debug.
What is the correct way to access the resources in different views?
Here a screenshot of the solution in Visual Studio:
If you're having a single-project solution, I'd recommend you either to create a Shell - as the Microsoft example recommends, or to use the App.xaml.cs class for localization purposes.
First, in the constructor of either class, get the current ResourceLoader:
// E.g use the static constructor of your App class
static App()
{
_resourceLoader = new ResourceLoader();
}
Now getting a resource (e.g. a text) is very easy:
public static string GetLocalizedString(string key)
{
return _resourceLoader.GetString(key);
}
Now you can load a string form the default resource dictionary:
tbSimpleInput1.Text = App.GetLocalizedString("dataToolDiameter");
Please note: this only works as long as you use the default pattern for localization in your project. If you use different resource files, you'd have use an overload of the ResourceLoader constructor.

Dotnetnuke Custom Module Settings

I have created a dotnetnuke module, it has multiple controls wrapped in a single moduleNow i want to access the settings variable across module, say for example i have a setting for dateformat, now the dateformat user selects should be used throughout moduleIt works fine with the view control which comes by default with Dotnetnuke (ChrisToc Template)But when i add new control it does not works, i also added proper inherits, it never throws compile error (in case it does not gets proper namespace)
Below is the code i am using:
public partial class ViewEntry : WireModuleBase
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("SETTINGS: " + Settings["WireDateFormat"]);
}
}
Any help will be appreciated
I don't ever use the Setting dictionary in my module views. First, it leaves you open to code errors by having to hardcode the key string when accessing the setting. Second, it makes it hard to share with you business logic or other views. My preferred pattern for settings is to create an interface and class for my settings that provides class attribute for my settings and performs the plumbing calls to DNN core to get and set those settings.
Follow this link to a Codeplex project where you will find a class SettingsRepository and ISettingsRepository interface.
Once you modified the public properties for your settings (ie: WireDateFormat) into the class and interface, you can then use it in your module settings implementation.
Get the setting:
ISettingsRepository settingsCtrl = new SettingsRepository(this.ModuleId, this.TabModuleId);
txtSetting1.Text = settingsCtrl.Setting1;
Write the setting
ISettingsRepository settingsCtrl = new SettingsRepository(this.ModuleId, this.TabModuleId);
settingsCtrl.Setting1 = txtSetting1.Text;
Once the settings is stored (in this case using the TabModuleId, but you can use the ModuleID constructor overload if you want to share the setting across modules on a page), you can use the same "get" code in any of your module views or business logic.

how to use different module in zend framework 2 (zf2)

I have 2 different module in project
1)Album
2)User
I want use some classes of User module in 'Album' Module.
Please help me how I can configure it.
Thanks and Regards,
Ashish
Service Classes should be accessible via the ServiceManager. In case Classes are made available there, either as factories or invokables, you should be able to call them from your Controller like this:
$this->getServiceLocator()->get('name-of-your-service');
Otherwise if it's only classes you need to use, you can simply import and use them like
namespace Othermodule;
use My\Module\Class\Name;
class OtherModuleClass {
public function someAction()
{
new Name();
// Or fully qualified inline
new \Third\Module\Class\Name();
}
}

Accessing Orchard CMS settings programatically inside a Module

I am writing an Orchard CMS module within a multi-tenant application.
I would like to be able to access the settings declared when the tenant was set up, namely the DB table prefix which i'd like to use as a unique identifier for the current tenant in other areas of my system.
Is there an API/Helper I can query for these settings?
Cheers.
Get the site item from the work context. It has all the settings as parts. For the table prefix specifically it's a little different: you need to inject ShellSettings. But I would question the need to do that first...
I have found this, if it helps:
private readonly ISiteService _siteService;
public MyController(ISiteService siteService)
{
_siteService = siteService;
}
public void MethodExample(){
var myVar = _siteService.GetSiteSettings().BaseUrl;
}

How to access database from configure method of a symfony task

You can create a symfony "task" by extending sfBaseTask; see http://www.symfony-project.org/cookbook/1_1/en/tasks for more details.
However, I cannot see how to set up a database connection in the configure section. I want to do this so that I can have the detailedDescription property show some options that are only defined in the database.
What is the best way to do this?
If you check out the way symfony creates a custom Task Skeleton (./symfony generate:task yourTaskName), you would see code that looks like this inside the execute function:
protected function execute([..])
{
$databaseManager = new sfDatabaseManager($this->configuration);
$connection = $databaseManager->getDatabase($options['connection'])->getConnection();
[..]
The problem with this code is that it uses the default configuration, but if you know what connection you want to open (check your database.yml or schema.yml to figure out the name) it should be really easy, with code that looks like this:
protected function configure()
{
$databaseManager = new sfDatabaseManager(sfProjectConfiguration::getApplicationConfiguration('frontend'‌​, 'prod', true));
$connection = $databaseManager->getDatabase("the_name_of_your_connection")->getConnection();
[..]
Then you can access your models the usual way, e.g.:
$myItem = Doctrine_Core::getTable('item')->find(14);
echo $myItem->getId();
If you are using Doctrine, the best way to do that is defining a method into the php model file. The model's files are located into /PROJECT/lib/model/doctrine/MODEL_NAMETable.class.php
Be carefull with the MVC model!
Once you have your own method, the way to call it is: Doctrine_Core::getTable('TABLE_NAME')->miNewMethod($params-if-any);
I hope I'll help you!

Resources