Setting database parameters in Zend 3 - mysql

I'm a serious newbie as it comes to Zend and I'm now forced to work with Zend 3 (and learn it). Fellow developers have done parts of the application and now I'm cloning it on my side.
I receive "Database not selected" in the error log - I have set database.local.php and I think they've set everything else. Credentials are correct.
I'm working on Windows.
Is there anything else I could be missing as it comes to settings or database connection?
Thanks. I will provide any additional info if needed.

As we're dealing with both Zend Framework AND a configuration issue, for your next question, please make sure to also include file paths and such.
I'm proceeding with this answer under the assumption that you've created your file here: /config/database.local.php.
Note: using ZF3 myself, I, of course, tried to find your error message "Database not selected", however it comes back with no results. Make sure you copy and paste error messages so users of any framework, cms or another system can more easily help you out.
You'll find the problem you're facing in the application.config.php file (in the /config folder. In here you'll find the following config:
// Retrieve list of modules used in this application.
'modules' => require __DIR__ . '/modules.config.php',
// These are various options for the listeners attached to the ModuleManager
'module_listener_options' => [
// ... other config
// An array of paths from which to glob configuration files after
// modules are loaded. These effectively override configuration
// provided by modules themselves. Paths may use GLOB_BRACE notation.
'config_glob_paths' => [
realpath(__DIR__) . '/autoload/{{,*.}global,{,*.}local,{,*.}deploy,{,*.}development}.php',
],
// ... other config
],
Any of the *.local.php or *.global.php config files should be placed in /config/autoload/. Though, if you modify the above config, you could technically place it wherever you'd like.
Next, make sure you have the Zend\Db module enabled in your configuration. Open up the /config/modules.config.php file and make sure Zend\Db is in the list of Zend modules to be loaded in.
Lastly, you have not provided the config you used, so I'm assuming you made a mistake there. Use something like the config below in your /config/autoload/database.local.php file. Technically you could split this over 2 files; a global and a local file. Local files are (/should) not be committed into version control history and as such can contain usernames and passwords. Any other config, such as using Pdo for a driver could go into global config.
'db' => [
'driver' => 'Pdo',
'dsn' => 'mysql:dbname=zf3;hostname=localhost',
'username' => 'root',
'password' => 'root',
'driver_options' => [
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
],
],

Related

I want to get the backend url from frontend without using hardcoded URLs yii2

'urlManagerBackend' => [
'class' => 'yii\web\urlManager',
'baseUrl' => 'http://backend.test',
'enablePrettyUrl' => true,
'showScriptName' => true,
],
then I want to display the image saved under uploads directory
<img src="<?= Yii::$app->urlManagerBackend->baseUrl; ?>/uploads/logo.jpg>
the problem is this url must not be hardcode like this:
'baseUrl' => 'http://backend.test',
The only way how to dynamically determine the domain of the other application (for example the backend from your frontend) would be by parsing the web server's configuration files.
The domain for current application (the one you can get with Url::base(true)) is determined from the request headers or variables set by web server. But those are available only for current application, not for any other application even if they are part of same project.
If you want to parse web server's configuration files than you will have to face three major challenges:
Different web servers have different syntax for configuration files.
Configuration files might be located anywhere.
You might not have access rights to read the configuration files.
So it might be better to try to think about some workaround instead of insisting on determining the domain dynamically.
Make a deploy script that would ask for the backend domain. The one who will be deploying your application on production servers will know the domain for the backend application and can enter it during deployment process. The deploy script will then set the entered backend domain in your configuration files.
Make a page in backend that must be visited before accessing the frontend application. You can determine the domain for backend when the page in backend is visited then set that domain in frontend configuration files. If the frontend is accessed before the domain for backend is set you will only display the notice that the backend page must be accessed first.
In the config folder there should be a file called params.php. If you have something like this
<?php
return [
'adminEmail' => 'admin#example.com',
'baseUrl' => 'http://backend.test',
];
You can use it in your code like this
<img src="<?= Yii::$app->params['baseUrl']; ?>/uploads/logo.jpg>
Then when you move to live, you just need to edit the params.php file.
Too long comment so I need to put it here.
But I'm just wondering in which case that makes sense, except if you are creating web applications, sites, ..., through your application, which I doubt you do.
You know your local domain (use local environment and put urls).
You will know your dev domain (use dev environment and put urls).
You will know your production domain (use prod environment and put urls).
You can also have multiple applications inside yii2 project, so for example,
10 applications across 3 envs, that is 30 urls which you will enter in you configs.
Can you please tell me, how you will access your app if url is dynamically determined -> without using anything else except Yii?
What is your step? You are typing in your browser what? Then we can proceed. Maybe we misunderstand each other.
urlManagerBackend' => [
'class' => 'yii\web\urlManager',
'baseUrl' => 'http://backend.test',
'enablePrettyUrl' => true,
'showScriptName' => true,
]
If you are wondering you can also have multiple urlManagerBackend components across Yii2 environments. Just like with params. Add it on multiple corresponding places at config. So in specific environment you place at same file only key => values which you need to override.
You could simply use Assets and Aliases for this:
If you have a backup/web/uploads/ folder in which you save images uploaded via your backend and you'd like to display those images on your frontend.
Create a new asset file in your frontend/assets/, let's call it BackendAsset.php:
<?php
namespace frontend\assets;
use yii\web\AssetBundle;
class BackendAsset extends AssetBundle {
public $sourcePath = '#backend/web/uploads';
}
where $sourcePath is the backend-folder (source) you'd like to access on the frontend. The #backend alias is predefined in the advanced template, so we'll use it.
Now in our view we can simply use the BackendAsset:
<?php
use frontend\assets\BackendAsset;
$backend = BackendAsset::register($this);
?>
and now we can easily display a file, let's say backend/web/uploads/somefile.jpg:
<img src="<?= $backend->baseUrl . '/somefile.jpg' ?>" >
NOTE: Using the asset in this way copies all the files from the backend/web/uploads to an asset folder in the frontend. To prevent that, you can tell your application not to copy the files, but to link to them (creating SymLinks) instead, unsing linkAssets (yii2 docu):
In your app configuration (in this case frontend/config/main.php), set the linkAssets parameter to TRUE:
'components' => [
'assetManager' => [
'linkAssets' => true,
]
]
I solve this problem by saving the full url in the database.
What about putting a reverseproxy (e.g. nginx) in front of the frontend-server?
Could be configured like:
http://frontend/backend/* -> forwards everyhing to the backend service, the rest will still go to the frontend server.
The configuration (in this case the location of the backend server) of this reverseproxy can be changed any time (also after deployment).
Could that be a viable scenario?

Cake PHP 3 debug_kit panel

After install CakePHP3 ver. 3.6.2, debug_kit don't show panel. in the log file
"Warning: DebugKit is disabling itself as your host newtest.my is not in the known safe list of top-level-domains (localhost,dev,invalid,test,example,local). If you would like to force DebugKit on use the DebugKit.forceEnable Configure option."
How i can enable debug panel? Thank's!
This question has already been answered by Greg Schmidt but for clarity for anyone else wondering about this in the future: basically what is happening is CakePHP has determined that the host you are using is unsafe, and has therefore disabled the Debug Kit. CakePHP also provides a workaround for this by providing the DebugKit.forceEnable key to override this default behavior. It is recommended that you do this in either app.php or, if you have kept the default app.php as-is and provided an override file like app_local.php as you should, you can do it there as well:
'DebugKit' => [
'forceEnable' => true,
// other config options
]
CakePHP provides a tiny explanation of this in Their Cookbook
An other way to achieve this would be to do something like this in your bootstrap.php
if (Configure::read('debug')) {
Configure::write('DebugKit.forceEnable', TRUE);
Plugin::load('DebugKit', ['bootstrap' => TRUE]);
}

Cakedc Users Could not load configuration file

I'm using CakeDC's Users Plugin for authentication.
I've followed all the steps of installation as documented here, but i'm getting this error:
I've performed the following steps:
composer require cakedc/users
composer require league/oauth2-facebook:#stable
composer require league/oauth2-google:#stable
bin/cake migrations migrate -p CakeDC/Users
In config/bootstrap.php
Configure::write('Users.config', ['users']);
Plugin::load('CakeDC/Users', ['routes' => true, 'bootstrap' => true ]);
Configure::write('Users.Social.login', true); //to enable social login
Load the Component in your src/Controller/AppController.php, and use
the passed Component configuration to customize the Users Plugin:
$this->loadComponent('CakeDC/Users.UsersAuth');
Update: I've removed
Configure::write('Users.config', ['users']);
this line from my bootstrap as i'm using the default users.php file which is present inside the plugin now.
But i get this error now:
Invalid provider or missing class (League\OAuth2\Client\Provider\LinkedIn)
I can get rid of this error by disabling social login (which is not what i want to do):
Configure::write('Users.Social.login', false);
After disabling the social login i get this error:
Error: A route matching "array ( 'plugin' => 'CakeDC/Users', 'controller' => 'Users', 'action' => 'login', 'prefix' => false, '_ext' => NULL, )" could not be found.
Any help would save my day.
#ndm was right, Step 5 is for Configuration, when installing with composer removing the following 2 lines fixes the error before the Migration Step:
Configure::write('Users.config', ['users']);
Plugin::load('CakeDC/Users', ['routes' => true, 'bootstrap' => true ]);
Then after the migration add these lines back in to continue the installation.
Step number 5 is customization - check the header in the docs that you've linked. So that's not actually a required installation step.
The problem should be rather easy to figure from the naming, the error that you're encountering, and the stacktrace (just check what's being done in each of the frames) - setting Users.config is to be used to define custom config files, the one you've defined doesn't exist (or isn't reabable), hence the error.
collection((array)Configure::read('Users.config'))->each(function ($file) {
Configure::load($file);
});
https://github.com/CakeDC/users/blob/3.2.0/config/bootstrap.php#L21-L23
So either don't do that and define the configuration elsewhere (being it in your app config, or wherever), or create the missing users.php config file and put your users plugin configuration in there.
See also
https://github.com/CakeDC/users/.../Configuration.md#overriding-the-default-configuration

After uploading Laravel to server I get an error message on my routes page

I'm almost done with a Laravel project I'm working on and am wanting to try it out on an actual server.
However after I loaded the entire project (slower than using composer but I was hoping to keep this as simple as possible the first time I tried this) I can't even log in as I'm getting a "syntax error, unexpected '['" error message with the debug window pointing to this code:
Route::get('login', [
'as' => 'login',
'uses' => 'SessionsController#create'
]);
I tried changing it to
Route::get('login', array(
'as' => 'login',
'uses' => 'SessionsController#create'
));
but after I changed it and uploaded the file again it still looked like the original code. To make things more confusing the code should work either way, unless I am missing something.
If anyone can point out 1.)the reason for the error message - the project runs fine on my local server and 2.)why the file does not seem to be updating when I send in a new version it would be greatly appreciated! Thanks!
Your actual server is running PHP 5.3
Your local server is running PHP >=5.4
The short array syntax [] was added in PHP 5.4. See change log here.

How to change SMTP details in Typo3 directly from directory?

Quick Question!
I need to change the SMTP details in a Typo3 site. Normally, you can do this by going to the install tool > all configuration.
That however is password protested and I don't know it! (The guy who does know it is not available)
Can I change these details directly from a file in the FTP server? If so, which file? I can't find it, and any documentation I've checked out doesn't help!
Ty!
the configuration from the install tool is stored in typo3conf/localconf.php (up until version 4.7) or in typo3conf/LocalConfiguration.php (since version 6.0).
The configuration regarding SMTP has to be put into $TYPO3_CONF_VARS['MAIL']:
$TYPO3_CONF_VARS['MAIL'] = array(
'transport' => 'smtp',
'transport_smtp_server' => 'smtp.yourdomain.org',
'transport_smtp_encrypt' => 'ssl', /* Usually available: ssl, sslv2, sslv3, tls. Check stream_get_transports(). */
'transport_smtp_username' => 'username',
'transport_smtp_username => 'password',
);
The formatting of the generated file is different in the two versions, but the array structure is the same. Be aware that changes to the localconf.php/LocalConfiguration.php might be overwritten by the install tool.
In addition to #jost answer, you may temporary set in your localconf:
$TYPO3_CONF_VARS['BE']['installToolPassword'] = 'bacb98acf97e0b6112b1d1b650b84971';
which corresponds to well-known 'joh316' and get access to Install Tool.
After you done with changes there, don't forget to restore old Install Tool password hash!
IN Your localconf.php add
$TYPO3_CONF_VARS['MAIL']['transport'] = 'smtp';
$TYPO3_CONF_VARS['MAIL']['transport_smtp_server'] = 'smtp.gmail.com:465';
$TYPO3_CONF_VARS['MAIL']['transport_smtp_port'] = '465';
$TYPO3_CONF_VARS['MAIL']['transport_smtp_encrypt'] ='ssl'; # requires openssl in PHP
$TYPO3_CONF_VARS['MAIL']['transport_smtp_username'] = '*****#gmail.com';
$TYPO3_CONF_VARS['MAIL']['transport_smtp_password'] = '*****';
then in your php file use
$mailContent = $mailcontent;
$mailContent = ($mailContent);
// Create the Mailer using your created Transport
$mail = t3lib_div::makeInstance('t3lib_mail_Message');
$mail->setFrom(array('sender email' => 'sender name'));
//$mail->setBcc(array($this->bcc => $this->bcc));
$mail->setSubject($subject);
$mail->setBody($mailContent,'text/html');
$mail->setTo(array('reciever email' => 'name'));
$mail->send();