So I'm trying to use the Yii2 reCaptcha widget: http://www.yiiframework.com/extension/yii2-recaptcha-widget/
However, when setting the validation rule for it
['reCaptcha'], \himiklab\yii2\recaptcha\ReCaptchaValidator::className(), 'secret' => Yii::$app->params['reCAPTCHA.secretKey']
I get the error Class 'himiklab\yii2\recaptcha\ReCaptchaValidator' not found. I'm quite new to Composer and Yii2, so I'm not sure what I'm missing.
composer.json
{
"autoload" : {
"psr-4" : {
"Gaiatools\\Yii\\" : "src"
}
},
"name" : "gaiatools/site",
"require" : {
"php" : ">=7.0",
"himiklab/yii2-recaptcha-widget" : "*"
}
}
vendor/composer/autoload_psr4.php
// autoload_psr4.php #generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'yii\\composer\\' => array($vendorDir . '/yiisoft/yii2-composer'),
'yii\\' => array($vendorDir . '/yiisoft/yii2'),
'himiklab\\yii2\\recaptcha\\' => array($vendorDir . '/himiklab/yii2-recaptcha-widget'),
'cebe\\markdown\\' => array($vendorDir . '/cebe/markdown'),
'Gaiatools\\Yii\\' => array($baseDir . '/src'),
);
Add this line to require section in project-directory/composer.json file
"himiklab/yii2-recaptcha-widget" : "*"
Then run in project directory command:
composer update
Run the following command in a terminal inside your project directory. It will be added automatically in composer.json file.
composer require --prefer-dist "himiklab/yii2-recaptcha-widget" "*"
Often you get the error of class not found when the file containing the class definition is not added in current code using namespaces.
Please ensure that you have added the required namespace in file where you are setting the validation rule with following code at the top of file
use himiklab\yii2\recaptcha
Hope this will solve your problem
Related
When you install a plugin with composer, by default it puts it into ROOT/vendor/[username]/[plugin-name]. This also updates ROOT/vendor/cakephp-plugins.php with something like
return [
'plugins' => [
'[UserName]/[PluginName]' => $baseDir . '/vendor/[username]/[plugin-name]/'
]
];
This apparently also makes it so that your plugin's namespace should be something like.
namespace [Username]\[PluginName]\Controller;
And when you do a redirect (as an example) you refer to it with something like...
$this->redirect(['plugin' => '[Username]/[PluginName]', 'controller' => '[Controller]', 'action' => 'index']);
What is the best practice for removing [Username] from when you reference a plugin that you install with composer?
The best practice is simply to remove your username from the autoload parameter in your plugin's composer.json file.
It looked like this::
"autoload": {
"psr-4": {
"Username\\PluginName\\": "src"
}
},
It should look like this
"autoload": {
"psr-4": {
"PluginName\\": "src"
}
},
I have a CSV file, and I want to import it in my Elastic Search.
I am on Windows 10 and I also have a Kibana be able to browse data once imported. I use Logstash to try to make this import.
All of my services (Kibana, ES and Logstash) are running on my localhost.
I tried with a the following Logstash configuration file (my csv file is in the correct path):
input {
file {
path => ["E:\Programmes\Logstash\logstash-2.2.0\data\*.csv"]
start_position => "beginning"
}
}
filter {
csv {
columns => ["billing_entity","invoice","company","username","reference","line_number","recipient_number","zone","network","date","time","country","duration","cost","currency","call_origin","billing_type"]
separator => ";"
}
#grok {
# match => { "call" => "%{WORD:billing_entity} %{WORD:invoice} %{WORD:company} %{WORD:username} %{WORD:reference} %{NUMBER:line_number} %{NUMBER:recipient_number} %{WORD:zone} %{WORD:network} %{DATE:date} %{TIME:time} %{WORD:country} %{WORD:duration} %{NUMBER:cost} %{WORD:currency} %{WORD:call_origin} %{WORD:billing_type}" }
#}
}
output {
elasticsearch {
action => "index"
index => "call_samples"
#index => "call-%{+YYYY.MM.dd}"
hosts => "localhost"
workers => 1
}
}
As you can see I tried to use 'csv' or 'grok' filter.
Then I launched in verbose mode logstash with this configuration file :
logstash.bat -f ..\conf\logstash.conf -v > logfile.txt
EDIT : after each try, I delete the generated sincedb files to simulate changes. But anyway I noticed they are empty
But in the logs I see nothing relevant :
message=>"Using mapping template from"
message=>"Attempting to install template"
message=>"New Elasticsearch output"
message=>"Registering file input"
message=>"No sincedb_path set,generating o....
message=>"Using mapping template from ...
message=>"Attempting to install template"
message=>"New Elasticsearch output"
message=>"Starting pipeline"
message=>"Pipeline started"
Quite alike my file is ignored .... I also tried several indexes , etc ... it will never import data.
To check if data is present I make query on localhost:9200 or I browse Kibana search bar "Index name or pattern" with the index "call_samples".
Can anyone help me on this please ? I'm stuck at this point ... Thanks
EDIT 2 :
Ok I'm dumb on this one, I just wanted to redirect the logs streams to a file when I was launching logstash :
logstash.bat -f ..\conf\logstash.conf -v > logfile.txt
But it was probably breaking the input file from being imported. So I just removed the part where I redirect on file :
logstash.bat -f ..\conf\logstash.conf -v
Now, my index is correctly created, but no data is being imported ...
It was an encoding issue, and even in verbose mode, it never told me it was failing or something ... not even a little clue.
So I tested with a new test file encoded in UTF-8 and it worked well ...
anyone who can help me to fix this problem.....i got this error after i update my composer at my yii2 application..
also i got error messsage this:
* #return array the path directory and the URL that the asset is published as.
* #throws InvalidParamException if the asset to be published does not exist.
*/
protected function publishDirectory($src, $options)
{
$dir = $this->hash($src);
$dstDir = $this->basePath . DIRECTORY_SEPARATOR . $dir;
if ($this->linkAssets) {
if (!is_dir($dstDir)) {
symlink($src, $dstDir);
}
} elseif (!empty($options['forceCopy']) || ($this->forceCopy && !isset($options['forceCopy'])) || !is_dir($dstDir)) {
$opts = array_merge(
$options,
[
'dirMode' => $this->dirMode,
'fileMode' => $this->fileMode,
]
);
My 2nd problem after i run composer diagnose...i got message:
checking composer.json: FAIL..
actually what the problem of this...
Set linkAssets to false here:
https://github.com/trntv/yii2-starter-kit/blob/master/common/config/web.php#L6
It is a common problem about php symlink() function in Windows systems. There are many posts around the web about it
I'm a newbie using cakephp-3.0.
I'm planing to show different templates-views according to user's browser/agent.
In cakephp2.x the code can be like below:
if ($this->DisplayModeService->hasSpViewSupport()) {
App::build([
'View' => [APP . 'View/SmartPhone/', APP . 'View/'],
]);
}
but in cakephp3.0 it's in app.php :
return [
'App' => [
'paths' => [
'templates' => [
APP . 'Template' . DS . 'SmartPhone' . DS,
APP . 'Template' . DS,
],
],
],
];
But I want to change the template route only if the page has smartPhone version.
In the case above it jump into SP version anyway.
(for I wanna keep the same name for the same page )
ex:
/Template/SmartPhone/profile.ctp, /Template/profile.ctp.(has SP/PC Version)
/Template/news.ctp (PC Version only)
can it be possible?
You would better use $this->request->is('mobile'), and Themes
I have a console command to generate user report. I want to call the same from my web application. I am using Yii 2.0.0 beta version.I tried to follow answers given in this post How to call a console command in web application action in Yii?
Since Yii 2.0 structure is very different from Yii 1.1 ,I get errors if I try to include command/userReportController.php .Can someone guide me on this?
You should use an extension like https://github.com/vova07/yii2-console-runner-extension
I think this is the simplest solution:
$controller = new YourConsoleController(Yii::$app->controller->id, Yii::$app);
$controller->actionYourConsoleAction();
use this code:
$application = new yii\console\Application($config);
$application->runAction('controller/action');
I'm using this method instead of yii console command, because I'm running Yii on managed VPS where unix commands are not supported in cron, only php scripts.
To run it this way instead of console, the yii configuration must be initialized first, of course:
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/common/config/bootstrap.php');
require(__DIR__ . '/console/config/bootstrap.php');
$config = yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/common/config/main.php'),
require(__DIR__ . '/common/config/main-local.php'),
require(__DIR__ . '/console/config/main.php'),
require(__DIR__ . '/console/config/main-local.php')
);
Let's say your action is called file/convert, and you want to run it in the background:
$cmd = "cd /home/site.com/public_html/yii && nohup php yii file/convert >/dev/null &";
shell_exec( $cmd );
yii2-console-runner-extension keeps loading.
Try this:
It's yii (without ext, not yii.bat)
Make sure that php folder added to PATH variable (Windows)
$op = shell_exec ( 'absolute/path/to/yii ' . 'cache/flush-all' );
\yii\helpers\VarDumper::dump($op, 10, 1);
Output:
The following cache components were processed:
* cache (yii\\caching\\FileCache)
If you really want to run Console controller by Web controller likes migrate:
public function actionMigrate()
{
// Keep current application
$oldApp = \Yii::$app;
// Load Console Application config
$config = require \Yii::getAlias('#app'). '/config/console.php';
new \yii\console\Application($config);
$result = \Yii::$app->runAction('migrate', ['migrationPath' => '#app/migrations/', 'interactive' => false]);
// Revert application
\Yii::$app = $oldApp;
return;
}
Above sample code is for yii2-app-basic template, you could change path for yii2-app-advanced template.