I have an admin module which I'm using for backend user management etc...
I would like to have the 'rights' extension nested under this admin module and be able to get to it with mysite.com/index.php?r=admin/rights
Apparently I need to declare child modules in the parent so under the AdminModule init, i've set:
$this->setModules(array(
'rights'=>array(
'install'=>true, // rights - Enables the installer
'baseUrl'=>'/admin/rights',
'debug'=>true,
),
));
I've also tried importing from AdminModule init: (clueless on this one)
$this->setImport(array(
'admin.models.*',
'admin.components.*',
'admin.modules.rights.*',
'admin.modules.rights.components.*',
));
Also I've tried declaring the module in the main.php config:
'admin'=>array(
'modules'=>array(
'rights'=>array(
'install'=>true, // rights - Enables the installer
'baseUrl'=>'/admin/rights',
'debug'=>true,
),
),
),
And even importing it there:
'import'=>array(
'application.models.*',
'application.components.*',
'application.modules.admin.*',
'application.modules.admin.modules.rights.*', // rights
'application.modules.admin.modules.rights.components.*', // rights
),
Anywho, no matter what I've tried so far, I cannot get to the rights module. It gives me Unable to resolve the request "admin/rights". when trying to get to admin/rights.
The extension works fine as an un-nested module at ?r=rights. Any ideas? I've not found many examples of the actual code when dealing with nested modules.
Could the problem be a missing route?
Try adding the following:
<module:\w+>/<controller:\w+>/<action:\w+>'=>'<module>/<controller>/<action>
I guess that you have multiple rights modules. To use particular one (from „deeper“ hierarchy) you must declare its class. Something like that:
'admin'=>array(
'modules'=>array(
'rights'=>array(
'class' => 'application.modules.admin.modules.rights.RightsModule'
),
),
),
Related
How to use WHMCS LocalAPI (InternaAPI)
Hi
I have a problem to use WHMCS LocalAPI
WHMCS Documentation is very poor and unclear about this problem
when I run this code a blank page appear and any thing is happened
<?php
require('../init.php');
require('../includes/api.php');
$command = 'AddOrder';
$postData = array(
'clientid' => '1',
'domain' => array('domain1.com'),
'billingcycle' => array('annually'),
'domaintype' => array('register',),
'regperiod' => array(1),
'nameserver1' => 'ns1.demo.com',
'nameserver2' => 'ns2.demo.com',
'paymentmethod' => 'zarinpalgw',
);
$adminUsername = 'myadminname'; // Optional for WHMCS 7.2 and later
$results = localAPI($command, $postData, $adminUsername);
print_r($results);
?>
I expected to add order after run this code
External API is very slow and not suitable for me for some reason such as
I have a dynamic IP and External API work with static IP because IP must be recognize in WHMCS->General setting->Security
The Internal API code in your example looks like it should work. Temporarily enabling PHP errors can help narrow down the exact cause of this issue (Setup > General Settings > Other > Display Errors), although I believe it is due to the way you are initializing the WHMCS environment in your PHP file.
WHMCS provides specific guidelines on building custom pages, which appears to be what you were trying to do in the example provided. Custom PHP files must be located in the root WHMCS directory, however require('../init.php'); indicates that your script is currently inside a subdirectory. You also should not be requiring api.php, as that is already being handled by init.php. Moving your script to the WHMCS root directory and commenting out the require('../includes/api.php'); line should hopefully fix the blank page issue.
Please note: the example you provided does not display the normal WHMCS client interface and does not check to see if the user is logged in. If that is functionality you will be needing as well, you can create a page with the same interface and functionality as a native WHMCS client area page. The following is a slightly modified version of the example code WHMCS provides in their guide for creating client area pages:
<?php
// Define WHMCS namespaces
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;
// Initialize WHMCS client area
define('CLIENTAREA', true);
require __DIR__ . '/init.php';
$ca = new ClientArea();
$ca->setPageTitle('Your Page Title Goes Here');
$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('mypage.php', 'Your Custom Page Name');
$ca->initPage();
// Uncomment to require a login to access this page
//$ca->requireLogin();
// Uncomment to assign variables to the template system
//$ca->assign('variablename', $value);
// Code to run when the current user IS logged in
if ($ca->isLoggedIn()) {
$clientName = Capsule::table('tblclients')->where('id', '=', $ca->getUserID())->pluck('firstname');
$ca->assign('clientname', $clientName);
// Code to run when the current user is NOT logged in
} else {
$ca->assign('clientname', 'Random User');
}
// Setup the primary and secondary sidebars
Menu::addContext();
Menu::primarySidebar('announcementList');
Menu::secondarySidebar('announcementList');
// Define the template filename to be used (without the .tpl extension)
$ca->setTemplate('mypage');
// Display the contents of the page (generated by the Smarty template)
$ca->output();
I want to use puppet to manage some servers. Even after reading dozens of documentation pages, it is not clear to me how to use modules and how to use them with hiera. As first experiment I wanted a user "admin" to be created on one node and found this module -> https://github.com/camptocamp/puppet-accounts
My /etc/puppet/hiera.yaml looks as simple as this
---
:backends:
- yaml
:hierarchy:
- node/%{::fqdn}
- common
:yaml:
:datadir: /etc/puppet/hieradata
My /etc/puppet/hieradata/node/node1.example.com.yaml contains this
---
accounts::users:
admin:
uid: 1010
comment: admin
accounts::ssh_keys:
admin:
comment: ad
type: ssh-rsa
public: AAAAAAAAAAAAAA
This worked after I put this in my /etc/puppet/manifests/site.pp
hiera_include('classes')
class
{
'accounts':
ssh_keys => hiera_hash('accounts::ssh_keys', {}),
users => hiera_hash('accounts::users', {}),
usergroups => hiera_hash('accounts::usergroups', {}),
}
accounts::account
{
'admin':
}
Is this good practice? To me it feels wrong to put that stuff into site.pp since it gets messed up when I later use more modules. But where else to put it? I also don't understand how this separates data from logic, since I have data in both, node1.example.com.yaml and site.pp (admin). Some help would be great..
To understand what hiera is, you should think simply that Hiera is a DATABASE for puppet, a database of Variables/values and nothing more.
For a beginner I would suggest to focus on other parts of the system, like how to create modules! and how to manage your needs (without complexity) and then slowly build the "smart" recipes or the reusable ones...
Your puppet will first sick for a file called sites.pp (usually is on your main $confdir (puppet.conf variable. I am not going to mention environments it is for later.)
e path is /etc/puppet inside that directory, you have a directory manifests. There is the place for your sites.pp
usually a sites.pp structure is:
node default {
include *module*
include *module2*
}
node /server\.fqdn\.local/ {
include *module2*
include *module3*
}
this means that you have a default Node (if the node name doesn't fit any other node, will use the default, otherwise it will use the regex matching of the node FQDN in this case server.fqdn.local.
The modules (module, module2 and module3) are stored inside the $modulespath set on your puppet.conf. In our case i will use the: /etc/puppet/modules
the tree will look like:
/etc/puppet/modules/
/etc/puppet/modules/module/
/etc/puppet/modules/module/manifests/
/etc/puppet/modules/module/manifests/init.pp
/etc/puppet/modules/module2/
/etc/puppet/modules/module2/manifests/
/etc/puppet/modules/module2/manifests/init.pp
/etc/puppet/modules/module3/
/etc/puppet/modules/module3/manifests/
/etc/puppet/modules/module3/manifests/init.pp
About
classes: https://docs.puppetlabs.com/puppet/latest/reference/lang_classes.html
generally what i explained but from puppet labs: https://docs.puppetlabs.com/puppet/latest/reference/dirs_manifest.html
Please note that the example from the README
class { 'accounts':
ssh_keys => hiera_hash('accounts::ssh_keys', {}),
users => hiera_hash('accounts::users', {}),
usergroups => hiera_hash('accounts::usergroups', {}),
}
is catering to users of Puppet versions before 3.x which had no automatic parameter lookup. With a recent version, you should just use this manifest:
include accounts
Since the Hiera keys have appropriate names, Puppet will look them up implicitly.
This whole thing still makes no sense to me. Since I have to put
accounts::account
{
'admin':
}
in a manifest file to create that user, what for is hiera useful in this case? It doesn't separate data from logic. I have data in both, the .yaml file (ssh keys, other account data) and in a manifest file (the snippet above). By using hiera I expect to be able to create that user inside /etc/puppet/hieradata/node/node1.example.com.yaml but this is not the case. What is the right way to do this? What for is the example hiera file of this module useful? Wouldn't it be easier create an account the old style way in site.pp?
I am building restful stateless API using Yii2... So far so good. Now I failed at rookie problem.
I have decided to make API application (preferred by Yii) and make API as a module. So my structure is:
- modules
-- v1
--- components
--- controllers
--- models
Inside v1 folder of course there is Module.php. In here I do authentication like:
$behaviors['authenticator'] = [
'class' => HttpBasicAuth::className(),
'auth' => function($username, $password) {
... get user's data from DB ...
[HERE]
}
];
and at point [HERE] I sotre user's ID in public variable.
So far so good...
So when I for example call v1/abc/index abc controller loads in inside that controller I would like to access user's ID stored at point [HERE]. Any idea?
To access module from controller, you should simply use $this->module.
And from a view : $this->context->module.
No need to use getModule() here.
Read more : http://www.yiiframework.com/doc-2.0/yii-base-controller.html#$module-detail
PS: to access module outside its controllers/views you could use :
Yii::app()->getModule('module');
Have you tried
$v1Module = Yii::app()->getModule('v1');
And then simply
echo $v1Module->yourPublicVariable;
I have just installed the yii-user-management module but when I try to access it via browser I get
Fatal error: Call to a member function get() on a non-object in ..../modules/user/models/YumUser.php on line 368
$relations = Yii::app()->cache->get('yum_user_relations');
Appreciate any help.
It seems like the yii-user-management module requires a cache component for it to work. So in your application config add the cache component as
'cache'=>array(
'class'=>'CDummyCache',
),
Here we are using CDummyCache copmponent which is, as its name says, acts as a dummy. You can replace it by any other cache components as described here
Thanks #dInGd0nG. Your answer works for me too. Just would want to remind people to follow his link. In the link, you will see the configure statement shall be added in
'components'=>array(
......
'cache'=>array(
'class'=>'CDummyCache',
),
)
I'm following the information here:
http://www.yiiframework.com/doc/guide/1.1/en/topics.logging
Please take a look at my log component on my dev machine configuration file:
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CProfileLogRoute',
'levels'=>'error, warning, trace, info, profile',
),
array(
'class'=>'CWebLogRoute',
'levels'=>'error, warning, trace, info, profile',
'showInFireBug'=>true,
),
),
Using CProfileLogRoute is of any use JUST AND ONLY IF we place something like this on our application code:
Yii::beginProfile('blockID');
...code block being profiled...
Yii::endProfile('blockID');
1)
IF the only purpose is to measure the speed, then what does those levels
'error, warning, trace, info, private'
really mean on this context ?
Thanks a lot in advance,
MEM
Looks like those are remnants from CLogRoute (a parent class) that are unused in the code:
http://code.google.com/p/yii/source/browse/tags/1.1.10/framework/logging/CProfileLogRoute.php
The only variable I tend to set got CProfileLogRoute is 'report':
http://www.yiiframework.com/doc/api/1.1/CProfileLogRoute#setReport-detail