I want to use yii2-solr extension in one of my projects. How can I configure this extension. Nothing is mentioned on the extension page. Has anyone used this extension? Any help would be appreciable. Thank you.
I found the extension on github repo . In readme file it is mention to configure it as follows:
'solr' => [
'class' => 'sammaye\solr\Client',
'options' => [
'endpoint' => [
'solr1' => [
'host' => '10.208.225.66',
'port' => '8983',
'path' => '/solr'
]
]
]
],
But after doing all this I am getting the following error:
Class 'Solarium\Client' not found
In one of its Client.php file the line is:
use Solarium\Client as SolrClient;
I checked all the files but Solarium namespace is not there.
yii2-solr depends on the Solarium library. If you installed yii2-solr via composer, it should have automatically downloaded it as dependency. Check github composer.json. If not, you'll have to install it manually, see packagist.
Related
This question already has an answer here:
Override Yii2 Swiftmailer Recipient
(1 answer)
Closed 5 years ago.
During the development and testing, I want the Yii2 mailer (swiftmailer) not to send emails to actual addresses, but replace it with developers` emails. Is there any setting in config to do it?
Just set the useFileTransport to true in component configuration for the development environment and all emails will not be sent but will be saved as files so you can easily test everything.
You should set configs for prod and dev environment.
Path for dev config (if you have advanced application template): yourProject/environments/dev/common/config/main-local.php and for prod: yourProject/environments/prod/common/config/main-local.php.
You may use EmailTarget class for logs.
Example of config for dev environment to reach the clue:
return [
'bootstrap' => ['log'],
'components' => [
...
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '#common/mail',
'useFileTransport' => true,//set this property to false to send mails to real email addresses
//comment the following array to send mail using php's mail function
],
'log' => [
'targets' =>
[
[
'class' => 'yii\log\EmailTarget',
'levels' => ['error'],
'except' => ['yii\web\HttpException:404'],
'message' => [
'to' => ['example#mail.ru'],
'from' => ['yourproject#mail.ru'],
'subject' => ' Errors ',
]
],
],
],
],
];
And similarly for prod environment but with different emails.
If you don't want to use EmailTarget class you may just set your emails for dev in params config here: yourProject/environments/dev/common/config/params-local.php.
And path for prod: yourProject/environments/prod/common/config/params-local.php
Params config example:
return [
'sendToEmails' => ['email1#mail.ru', 'email2#mail.ru']
];
And then you may use the variable in your code this way: Yii::$app->params['sendToEmails'] to get the array of emails to send messages to.
Don't forget to do php init command in your project after compliting your configs.
You may see the detailed docs about environments here.
Currently my url is http://localhost/halodocnew/frontend/web/index.php?r=site%2Flogin I want to change name folder frontend to client for all action.
Please help me
Thank all so much
Suppose you want to rename backend to admin the follow the following steps
1)Rename backend folder to admin
2)Update Bootstrap.php under common/config/Bootstrap.php
Yii::setAlias('#backend', dirname(dirname(__DIR__)) . '/backend');
To
Yii::setAlias('#admin', dirname(dirname(__DIR__)) . '/admin');
3)Update site controller namespace under admin/controller/siteController.php backend\controllers; to namespace admin\controllers;
4) Update main.php ubder admin/config
'controllerNamespace' => 'backend\controllers' to 'controllerNamespace' => 'admin\controllers'
For Quick solution:
Copy and Paste your frontend folder in same directory and rename it to client
Open halodocnew\common\config\bootstrap.php
Add alias: Yii::setAlias('client', dirname(dirname(__DIR__)) . '/client');
Access in browser:
http://localhost/halodocnew/client/web/index.php
Another Solution:
Go into halodocnew\environments\dev\
Copy & Paste frontend in this folder and rename it to client.
Then go to halodocnew\environments\prod\
Copy & Paste frontend in this folder and rename it to client.
Open halodocnew\environments\index.php
Find 'Development' => [
'path' => 'dev',
'setWritable' => [
'backend/runtime',
'backend/web/assets',
Add 'Development' => [
'path' => 'dev',
'setWritable' => [
'backend/runtime',
'backend/web/assets',
'client/runtime',
'client/web/assets',
Do same above for 'Production' => [
'path' => 'prod',
Go into your project root directory and run php init
Copy web and veiws folder from frontend to client
Open halodocnew\common\config\bootstrap.php
Add alias: Yii::setAlias('client', dirname(dirname(__DIR__)) . '/client');
Open browser and access your desired directory http://localhost/halodocnew/client/web/index.php
I don't think it is sooper dooper solution but I used these methods =:)
I want to create a file .env:
FACEBOOK_CLIENT_ID=*****
FACEBOOK_CLIENT_SECRET=*****
and use variable for config
'facebook' => [
'class' => 'yii\authclient\clients\Facebook',
'clientId' => env('FACEBOOK_CLIENT_ID'),
'clientSecret' => env('FACEBOOK_CLIENT_SECRET'),
],
I have found the solution.
I use package vlucas/phpdotenv.
Thank for all
You can archive this by Utilizing the enviroment constants. If you are using Yii2 advanced when you initialize your application as dev or production yii sets a constant YII_ENV as either dev or production in your index.php entry script.
If you are using yii basic you can set it as per your enviroment. For example we want to define config for dev.
We will proceed and edit our /web/index.php to
defined('YII_ENV') or define('YII_ENV', 'dev');
Then in our config file we would have the following
'facebook' => [
'class' => 'dektrium\user\clients\Facebook',
'clientId' => (YII_ENV_DEV ? 'Your key when in developent' : 'Your Key if not in developement'),
'clientSecret' => (YII_ENV_DEV ? 'Your key when in developent' : 'Your Key if not in developement'),
],
Refere to this for more details on Enviroment Constants http://www.yiiframework.com/doc-2.0/guide-concept-configurations.html#environment-constants
There's a package for Yii2 you can use for dotenv
https://github.com/yiithings/yii2-dotenv
Install:
composer require --prefer-dist yiithings/yii2-dotenv "*"
Usage:
Create a .env in project root directory
DB_HOST="localhost"
DB_NAME="yii2basic"
DB_USER="root"
DB_PASS="YourPassword"
config/db.php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host='. env('DB_HOST') .';dbname='. env('DB_NAME'),
'username' => env('DB_USER'),
'password' => env('DB_PASS'),
'charset' => 'utf8',
];
You could use the dotenv package offered by Symfony. https://symfony.com/doc/current/components/dotenv.html
using it in a PHP file.
use Symfony\Component\Dotenv\Dotenv;
$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/.env');
// You can also load several files
$dotenv->load(__DIR__.'/.env', __DIR__.'/.env.dev');
.env file
DB_USER=root
DB_PASS=pass
accessing the variables from the .env file
$dbUser = $_ENV['DB_USER'];
// you can also use ``$_SERVER``
I am trying to learn Yii 2 from a book (Web application development with Yii2 and PHP). Somewhere along the line it instructs me to install gii and create crud files with it.
When I installed with the following command:
php composer.phar require --prefer-dist "yiisoft/yii2-gii:*"
I have following error:
Invalid Parameter – yii\base\InvalidParamException
The file or directory to be published does not exist: /var/projectsRoot/crmapp/src/vendor/yiisoft/yii2/gii/assets
My bootstrap code:
//Define Yii debug mode
define (YII_DEBUG, true);
//Including composer autoloader
require (__DIR__ . '/../vendor/autoload.php');
//Including Yii framework
require (__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
//debugging for PHP
ini_set('display_errors', true);
//Getting Configuration
$config = require(__DIR__ . '/../config/web.php');
//Include and launch application
(new yii\web\Application($config))->run();
config file:
return [
'id' => 'crmapp',
'basePath' => realpath(__DIR__ . '/../'),
'components' => [
'request' => [
'cookieValidationKey' => 'your secret key here'
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false
],
'db' => require(__DIR__ . '/db.php')
],
'modules' => [
'gii' => [
'class' => 'yii\gii\Module',
'allowedIPs' => ['192.168.33.1']
]
],
'extensions' => [
require (__DIR__ . '/../vendor/yiisoft/extensions.php')
]
];
extensions file:
$vendorDir = dirname(__DIR__);
return array (
'yiisoft/yii2-bootstrap' =>
array (
'name' => 'yiisoft/yii2-bootstrap',
'version' => '2.0.5.0',
'alias' =>
array (
'#yii/bootstrap' => $vendorDir . '/yiisoft/yii2-bootstrap',
),
),
'yiisoft/yii2-gii' =>
array (
'name' => 'yiisoft/yii2-gii',
'version' => '2.0.4.0',
'alias' =>
array (
'#yii/gii' => $vendorDir . '/yiisoft/yii2-gii',
),
),
);
I digged it a little bit. It seems problem is about the alias of the assets folder.
In GiiAsset.php file, there is this codeblock:
...
class GiiAsset extends AssetBundle
{
public $sourcePath = '#yii/gii/assets';
...
which returns
/var/projectsRoot/crmapp/src/vendor/yiisoft/yii2/gii/assets
but it normally should return
/var/projectsRoot/crmapp/src/vendor/yiisoft/gii/assets
so it is adding an unnecessary yii2 to the path.
I tried to change the $sourcePath in extensions.php file, but changing the value here does not effect the result in any way.
Any ideas?
--UPDATE--
While I was fiddling with things, I tried to define the alias to force the correct value; as follows:
Yii::setAlias('#yii/gii', $vendorDir . '/yiisoft/yii2-gii');
when I try to run the application with this setting I get following error:
The file or directory to be published does not exist: /var/projectsRoot/crmapp/src/vendor/bower/bootstrap/dist
When I change the alias definition to this:
Yii::setAlias('#yii/gii', $vendorDir . '/yiisoft/yii2-gi');
I get following error:
The file or directory to be published does not exist: /var/projectsRoot/crmapp/src/vendor/yiisoft/yii2-gi
I'm quite confused with this behavior. What would be causing this?
I ended up with deleting my vendor folder and composer.json file, and creating it back with following content:
{
"require": {
"codeception/codeception": "*",
"fzaninotto/faker": "*",
"yiisoft/yii2": "*",
"yiisoft/yii2-gii": "*"
}
}
When I launched the gii, it again threw the following exception:
The file or directory to be published does not exist:
/var/projectsRoot/crmapp/src/vendor/bower/jquery/dist
I renamed the vendor/bower-asset folder to vendor/bower and it works now.
I probably messed up with something before without noticing, but I'm not certain why it is looking for bower, instead of bower-asset. Renaming the bower-asset to bower seems to solve it.
UPDATE
Thanks to jacmoe from the original Yii forum, it has finally solved.
It seems these two lines need do be present in composer.json in order to automatically create bower folder, instead of bower-asset.
"extra": {
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
}
Original conversation can be found at here:
These lines are automatically created when you install the basic application template, but when installing the bare code base, you need to manually write them.
I have similar problem with my app based on yii2-app-advanced, but separated from #common. Solution is just add vendorPath attribute to application config.
all:
I am testing unixODBC in Solaris 10 environments, and find if libodbc and MyODBC driver are dynamically linked with libltdl.so:
ldd /usr/lib/libodbc.so.2
libltdl.so.7 => /usr/local/lib/libltdl.so.7
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libthread.so.1 => /usr/lib/libthread.so.1
libc.so.1 => /usr/lib/libc.so.1
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1
libm.so.2 => /usr/lib/libm.so.2
/platform/SUNW,Sun-Fire-V240/lib/libc_psr.so.1
ldd /data/nan/mysql-connector-odbc-5.2.4-src/lib/libmyodbc5a.so
libodbc.so.2 => /usr/lib/libodbc.so.2
libthread.so.1 => /usr/lib/libthread.so.1
libm.so.2 => /usr/lib/libm.so.2
libodbcinst.so.2 => /usr/lib/libodbcinst.so.2
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1
libltdl.so.7 => /usr/local/lib/libltdl.so.7
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libc.so.1 => /usr/lib/libc.so.1
/platform/SUNW,Sun-Fire-V240/lib/libc_psr.so.1
sometimes it will connect MySQL server failed when starting up application. The log likes this:
[ODBC][6738][1361325895.588941][SQLConnect.c][1111]Can't open lib '/data/nan/mysql-connector-odbc-5.2.4-src/lib/libmyodbc5a.so' : file not found
[ODBC][6738][1361325895.588979][SQLConnect.c][1111]Can't open lib '/data/nan/mysql-connector-odbc-5.2.4-src/lib/libmyodbc5a.so' : file not found
After a while, the application runs OK.
But if libodbc and MyODBC driver aren't dynamically linked with libltdl.so:
ldd /usr/local/lib/libodbc.so.2
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libthread.so.1 => /usr/lib/libthread.so.1
libc.so.1 => /usr/lib/libc.so.1
libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1
libm.so.2 => /usr/lib/libm.so.2
/platform/SUNW,UltraAX-i2/lib/libc_psr.so.1
ldd /data1/susie/mysql/tools/test_static_modify/mysql-connector-odbc-5.2.3-src/lib/libmyodbc5a.so
libodbc.so.2 => /usr/local/lib/libodbc.so.2
libthread.so.1 => /usr/lib/libthread.so.1
libm.so.2 => /usr/lib/libm.so.2
libodbcinst.so.2 => /usr/local/lib/libodbcinst.so.2
libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1
libiconv.so.2 => /usr/local/lib/libiconv.so.2
libc.so.1 => /usr/lib/libc.so.1
/platform/SUNW,UltraAX-i2/lib/libc_psr.so.1
The application runs always OK..
So I think it may be a potential issue in unixODBC. Could anyone help to check it? Thanks very much in advance!
Best Regards
Nan Xiao
All unixODBC does is call dlopen and dlsym from libltdl, I wonder if there is some statics in the lib that is causing the problem. If you don't build unixODBC to use a exernal libltdl it uses its own version (from libtool), so again, it may be a conflict with them both hitting the same lib. You say you are using Solaris. Is the libltdl you are linking with from Sun?
What might be interesting is if you can get it to fail under truss so we could see just what the "file not found" is caused by.
I also wonder just what the MySQL driver uses libltdl for?