Custom paths in Zend Framework 2 configuration - configuration

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.

Related

CakePHP 3 quoting function names defined in 'fields' configuration of my find() call

I am querying a database table conveniently named order and because of that I had to set 'quoteIdentifiers' => true in my app.php configuration. However, when I'm putting function names into the fields configuration of my find() call, CakePHP quotes them too.
$orders->find('all', array(
'fields' => array(
'DATE(Orders.date_added)',
'COUNT(*)',
),
'conditions' => array(
'Orders.order_status_id <>' => 0,
),
'group' => array(
'DATE(Orders.date_added)',
),
));
The query above ends up calling
SELECT <...>, `DATE(Orders.date_added)` FROM `order` <...>
which obviously throws an error.
I googled a lot, tried this:
$orders = $orders->find('all', array(
'conditions' => array(
'Orders.order_status_id <>' => 0,
),
'group' => array(
'DATE(Orders.date_added)',
),
))->select(function($exp) {
return $exp->count('*');
});
and that didn't work either, throwing me some array_combine error.
Is there any way for me to un-quote those function names, while keeping the rest of the query quoted automatically? Here's what I'm trying to accomplish:
SELECT <...>, DATE(Orders.date_added) FROM `order` <...>
Please help.
You should use function expressions, they will not be quoted, except for arguments that are explicitly being defined as identifiers:
$query = $orders->find();
$query
->select([
'date' => $query->func()->DATE([
'Orders.date_added' => 'identifier'
]),
'count' => $query->func()->count('*')
])
->where([
'Orders.order_status_id <>' => 0
])
->group([
$query->func()->DATE([
'Orders.date_added' => 'identifier'
])
]);
I'd generally suggest that you use expressions instead of passing raw SQL snippets wherever possible, it makes generating SQL more flexible, and more cross-schema compatible.
See also
Cookbook > Database Access & ORM > Query Builder > Using SQL Functions

Install Yii2 extension manually without using Composer giving error of class not found

I want to install 2amigos/yii2-google-maps-library widget Manually.
I have added "2amigos/yii2-google-maps-library" : "*" in required section of composer.json and I have added 'dosamigos\\google\\maps\\' => array($vendorDir . '/2amigos/yii2-google-maps-library'), in composer autoload_psr4.php
I have added '2amigos/yii2-google-maps-library' =>
array (
'name' => '2amigos/yii2-google-maps-library',
'alias' =>
array (
'#dosamigos\google\maps' => $vendorDir . '2amigos/yii2-google-maps-library',
),
), code in extensions.php of composer.
And my view code is
<?php
use dosamigos\google\maps\LatLng;
use dosamigos\google\maps\services\DirectionsWayPoint;
use dosamigos\google\maps\services\TravelMode;
use dosamigos\google\maps\overlays\PolylineOptions;
use dosamigos\google\maps\services\DirectionsRenderer;
use dosamigos\google\maps\services\DirectionsService;
use dosamigos\google\maps\overlays\InfoWindow;
use dosamigos\google\maps\overlays\Marker;
use dosamigos\google\maps\Map;
use dosamigos\google\maps\services\DirectionsRequest;
use dosamigos\google\maps\overlays\Polygon;
use dosamigos\google\maps\layers\BicyclingLayer;
/* #var $this yii\web\View */
$this->title = Yii::$app->name;
?>
<section>
<div class="container">
<div class="row">
<?php
$coord = new LatLng(['lat' => 39.720089311812094, 'lng' => 2.91165944519042]);
$map = new Map([
'center' => $coord,
'zoom' => 14,
]);
?>
</div>
</div>
</section>
But when i run this give me error
Class 'dosamigos\google\maps\LatLng' not found
Oh thanks got finally I got my solution. I added namespace with backslashes that cause error. I fixed
'2amigos/yii2-google-maps-library' =>
array (
'name' => '2amigos/yii2-google-maps-library',
'version' => '9999999-dev',
'alias' =>
array (
'#dosamigos/google/maps' => $vendorDir . '/2amigos/yii2-google-maps-library',
),
),
in extensions.php

Fatal error: Class 'mPDF' not found in myproject/vendor/kartik-v/yii2-mpdf/Pdf.php on line 281

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.

yii2 stripe include error (class not found)

Yii2 Framework.
Installed Stripe (https://github.com/stripe/stripe-php) by composer:
composer require stripe/stripe-php
And inserted to the view:
\Stripe\Stripe::setApiKey('sk_test_...');
$myCard = array(
'number' => '4242424242424242',
'exp_month' => 8,
'exp_year' => 2018
);
$charge = \Stripe\Charge::create(array(
'card' => $myCard,
'amount' => 2000,
'currency' => 'usd'
));
echo $charge;
And now framework can't find Class:
Error
Class 'Stripe\Stripe' not found
What should I do next?
Did you correctly include Composer's autoload file?
You should have a require statement similar to this near the beginning of your code:
require_once('vendor/autoload.php');
cf. Stripe's PHP library's README file and Composer's documentation.

Zend Framework 2 - Multiple sub domains cause problems

I am writing an application in Zend Framework 2 which is going to run from a few different subdomain, and I want to have a different module for each sub domain, to keep things tidy.
My problem is when I add more than 1 sub domain to the routing, it loses one of the sub domains.
eg: This setup works
testbed.localhost (module/Application)
a.testbed.localhost (module/A)
If I add an extra one it will the route all requests for a to the Application Index Controller
eg
testbed.localhost (module/Application), a.testbed.localhost (module/A), b.testbed.localhost (module/B)
This is the module.config.php for module/A
'router' => array(
'routes' => array(
'ads' => array(
'type' => 'Hostname',
'options' => array(
'route' => 'a.testbed.localhost',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'A\Controller',
'controller' => 'A\Controller\A',
'action' => 'index',
),
),
And this is the route in module.config.php in module/B
'router' => array(
'routes' => array(
'ads' => array(
'type' => 'Hostname',
'options' => array(
'route' => 'b.testbed.localhost',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'__NAMESPACE__' => 'B\Controller',
'controller' => 'B\Controller\B',
'action' => 'index',
),
),
Now the namespaces are correct in both the module.config.php files, what I have noticed is the sub domain a.testbed.localhost will work if I remove the reference to it from config/application.config.php
<?php
return array(
'modules' => array(
'Application',
'A',
'B', <--- A doesn't work if B is here
),
And if I swap A & B around in the modules array above, then B will get forwarded to the Application Module and A will work. So it seems to have problems with more than 1 sub domain. Has anyone got any ideas / come across the same thing?
This happens because your route names are the same. I would try a-ads and b-ads for route names and that should resolve your situation.
In the end the configuration is getting merged together. So it's like an array, when the last array is merged it overwrites anything before it.