I am running multiple cake apps which share one core/baseapp.
The basic structure is:
www/myapp1
www/myapp2
www/myapp3
www/baseapp
In each 'myapp' inside app.php I point the path for templates and plugins to the myapp and baseapp so that if no file is found in myapp the one from baseapp is used:
'App' => [
'imageBaseUrl' => 'img/',
'cssBaseUrl' => 'css/',
'jsBaseUrl' => 'js/',
'paths' => [
'plugins' => [ROOT.DS .'modules'.DS, BASEROOT . DS . 'modules' . DS],
'templates' => [APP . 'Template' . DS, BASEROOT.'/src/Template'.DS ],
],
],
(i include classes from baseapp inside composer.json which is probably not relevant for this question)
That works pretty well.
Question:
How can I make it include img, css and js in the same manner?
I want to have to folders where cake should search for the files for every app.
'App' => [ 'imageBaseUrl' => ['img/', BASEROOT. DS . 'webroot/img/']
does not work.
My Solution: In the folder webroot I made a link to BASEROOT (with the name 'baseroot') and then I made the File src/View/UrlHelper
class UrlHelper extends CakeUrlHelper{
public function webroot($file){
//code
if (file_exists(\Cake\Core\Configure::read('App.wwwRoot') . $file)) {
$webPath = $this->request->getAttribute('webroot') . $asset[0];
}else{
$webPath = $this->request->getAttribute('webroot').'baseroot'.DS.$asset[0];
}
//more code
}
}
Related
I am generating random data for project and for unit testing. So i want to use faker. But unable to how to use faker in yii2?
set this in your main config:
return [
'controllerMap' => [
'fixture' => [
'class' => 'yii\faker\FixtureController',
'templatePath' => '#common/tests/templates/fixtures',
'fixtureDataPath' => '#common/tests/fixtures/data',
],
// ...
],
// ...
];
use it like this:
$faker = Faker\Factory::create();
// generate data by accessing properties
echo $faker->name;
// 'Lucy Cechtelar';
echo $faker->address;
// "426 Jordy Lodge
// Cartwrightshire, SC 88120-6700"
echo $faker->text;
for more info check faker basic usage
and yii2 guide
I can't seem to send an email with laravel 5.4 on after setting the right configurations in config/mail.php. I'm using smtp driver here is summary of my files.
Here is the config/mail.php
<?php
return [
'driver'=>env('MAIL_DRIVER', 'smtp'),
'host'=>env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'info#afecamworld.org'),
'name' => env('MAIL_FROM_NAME', 'National President'),
],
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
'username' => env('MAIL_USERNAME', 'my-gmail-email'),
'password' => env('MAIL_PASSWORD', 'my-gmail-password'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
This is the SendActivationEmail class
<?php
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class SendActivationEmail extends Notification {
use Queueable;
protected $token;
public function __construct($token) {
$this->token = $token;
}
public function via($notifiable){
return ['mail', 'database'];
}
public function toMail($notifiable) {
return (new MailMessage)->subject('Activation Your Account')->greeting('Hello!')->line('You need to activate your email before you can login.')->action('Activate Email', route('activate_account', ['token' => $this->token]))->line('Thank you for joining our Online Community!');
}
}
?>
This is the top part of the error
(1/1) ReflectionException
Class Swift_Transport_Esmtp_Auth_CramMd5Authenticator does not exist
in DependencyContainer.php (line 309)
I will be grateful for any help to resolve this error on dreamhost, thanks.
The best way to resolve this problem is to delete the files in the vendor folder and redo composer install and composer update, that's how I fixed my problem
I have used kartik pdf extension to print my report in pdf format.Things are going well in my local computer but when i put my codes in server error appears like this:
Fatal error: Class 'mPDF' not found in myproject/vendor/kartik-v/yii2-mpdf/Pdf.php on line 281
In server i have uploaded yii2-mpdf folder inside kartik-v folder and also mpdf folder.
My code of controller for pdf print:
use kartik\mpdf\Pdf;
public function actionPearlFinancialReport()
{
$pdf = new Pdf([
//'mode' => Pdf::MODE_CORE,
'mode' => Pdf::MODE_UTF8,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
'content' => $this->renderPartial('_financial_report', ['model' => $model,'parameter'=>$parameter]),
'cssFile' => '#vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
'cssInline'=> '.kv-heading-1{font-size:15px;text-align:center;}',
'options' => ['title' => 'Pearl Financial Report'],
'methods' => [
'SetHeader'=>['Pearl Financial Report'],
'SetFooter'=>['{PAGENO}'],
]
]);
$response = Yii::$app->response;
$response->format = \yii\web\Response::FORMAT_RAW;
$headers = Yii::$app->response->headers;
$headers->add('Content-Type', 'application/pdf');
}
What to do?
Try this
'cssFile' => '#vendor/kartik-v/yii2-mpdf/src/assets/kv-mpdf-bootstrap.min.css',
Try to register this extension with composer:
For example my work directory is c:\xampp\htdocs\my-project
In a command prompt -> cd c:\xampp\htdocs\my-project
And register with this command:
C:\xampp\htdocs\my-project>php c:\xampp\htdocs\composer.phar require kartik-v/yii2-mpdf "dev-master"
I always register kartik's extensions with this metod, I hope want to be useful for you too.
I want to set different logpath for each module so that all errors, warnings, should be categorize with module name as parent folder.
i.e
runtime/logs/module_name/errors.log
runtime/logs/module_name/warnings.log
runtime/logs/module_name/info.log.
currently log component is configured in config/main.php
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'flushInterval' => 1,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['info'],
'categories' => ['common\modules\*'],
'logFile' => '#runtime/logs/common.modules.info.log',
],
],
]
I want to dynamically assign logFile path value in above application configuration file, so that if any error, warning, info is called in any module it will automatically pick that module name and logs the information.
You can add log target dynamically from controller or module init.
$target = new FileTarget();
$target->logFile = \Yii::getAlias('#runtime') . '/custom.log'
$target->categories = ['log-category']
\Yii::$app->getLog()->targets = [$target];
But I think will be better create new FileTarget class and moved static settings like categories into it.
Hello Stack Overflow Community
I am having some problems with my custom paths in my zend framework 2 module.
I've added following code to my module.config.php :
// custom configuration
'custom' => array(
'paths' => array(
'pickUpDir' => '/var/www/beam/public/in/',
'errorDir' => '/var/www/beam/public/error/',
'temporaryDir' => '/var/www/beam/module/Beam/temp/',
'archiveDir' => '/var/www/beam/module/Beam/archive/'
)
),
Now this works fine on my virtual developement server but i want it to work universaly, meaning if i put my Zend Framework application on a live server which has a different folder structure it should still work.
Is there a way to declare relative paths or something like that ?
Many thankx in advance
The magic constant __DIR__ will return the current directory which should be /..../Yourmodel/config/.
From there on you could just do:
'custom' => array(
'paths' => array(
'pickUpDir' => __DIR__ . '/../../public/in/',
'errorDir' => __DIR__ . '/../../public/error/',
//etc
)
),
Alternatively to cptnk's answer (which is also working), you can also use the get_cwd() function that will return you the root of your webapp, so that you can write stg like
'custom' => array(
'paths' => array(
'pickUpDir' => get_cwd() . '/public/in/',
'errorDir' => get_cwd() . '/public/error/',
//etc
)
)
as ZF2 defines the current working directory as root of your project.