Cakephp3 - Cant find $theme property that throws an error - cakephp-3.x

I have upgraded from Cakephp3 v3 to v3.3 (using Composer) and I get the following error:
Deprecated (16384): Property $theme is deprecated.
Use $this->viewBuilder()->theme() instead in beforeRender().
[CORE/src/View/ViewVarsTrait.php, line 103]
But I can't find in my files where $theme is used. I have searched all my files for the keyword $theme and beforeRender, no relevant results.
This error is shown in all my pages, so it must be some file that is included in each one.
I have already searched on google for this issue, no relevant results either.
Has anyone else had this problem?
Full error stack:
$viewClass = null
$builder = object(Cake\View\ViewBuilder) {
[protected] _templatePath => 'Users'
[protected] _template => 'login'
[protected] _plugin => null
[protected] _theme => 'Orange'
[protected] _layout => null
[protected] _autoLayout => null
[protected] _layoutPath => null
[protected] _name => null
[protected] _className => null
[protected] _options => []
[protected] _helpers => []
}
$validViewOptions = [
(int) 0 => 'passedArgs'
]
$viewOptions = [
'passedArgs' => []
]
$option = 'passedArgs'
$this = object(App\Controller\UsersController) {
theme => 'Orange'
name => 'Users'
helpers => []
request => object(Cake\Network\Request) {}
response => object(Cake\Network\Response) {}
paginate => []
autoRender => false
components => []
View => null
plugin => null
passedArgs => []
modelClass => 'Users'
viewClass => null
viewVars => []
Flash => object(Cake\Controller\Component\FlashComponent) {}
Auth => object(Cake\Controller\Component\AuthComponent) {}
[protected] _responseClass => 'Cake\Network\Response'
[protected] _components => object(Cake\Controller\ComponentRegistry) {}
[protected] _validViewOptions => [
(int) 0 => 'passedArgs'
]
[protected] _eventManager => object(Cake\Event\EventManager) {}
[protected] _eventClass => '\Cake\Event\Event'
[protected] _tableLocator => object(Cake\ORM\Locator\TableLocator) {}
[protected] _modelFactories => [
'Table' => [
[maximum depth reached]
]
]
[protected] _modelType => 'Table'
[protected] _viewBuilder => object(Cake\View\ViewBuilder) {}
}
$deprecatedOptions = [
'layout' => 'layout',
'view' => 'template',
'theme' => 'theme',
'autoLayout' => 'autoLayout',
'viewPath' => 'templatePath',
'layoutPath' => 'layoutPath'
]
$new = 'theme'
$old = 'theme'
Cake\Controller\Controller::createView() - CORE/src/View/ViewVarsTrait.php, line 103
Cake\Controller\Controller::render() - CORE/src/Controller/Controller.php, line 616
Cake\Http\ActionDispatcher::_invoke() - CORE/src/Http/ActionDispatcher.php, line 131
Cake\Http\ActionDispatcher::dispatch() - CORE/src/Http/ActionDispatcher.php, line 99
Cake\Routing\Dispatcher::dispatch() - CORE/src/Routing/Dispatcher.php, line 65
[main] - ROOT/webroot/index.php, line 21

Turns out that in AppController a custom theme (Orange in my case) needs to be declared as:
public function beforeRender(Event $event)
{
$this->viewBuilder()->theme('Orange');
}
and not like
public $theme = 'Orange';
Many thanks to #arilia for helping me with this.

Related

Get Id file uploaded google drive job queue laravel

i am making an image storage function with laravel job queue via googledrive. i am trying to initialize and store my photo. It works with the code:
$filePut = file_get_contents($this->path);
Storage::cloud()->put($this->name, $filePut);
but i can't get the return id
i am changing to another method and here is my 2nd code:
public function handle(GoogleClient $googleDrive)
{
dd($googleDrive);
$driveService = new \Google_Service_Drive($googleDrive);
$fileMetadata = new \Google_Service_Drive_DriveFile([
'name' => $this->name,
]);
$file = $driveService->files->create($fileMetadata, [
'data' => file_get_contents($this->path),
'uploadType' => 'multipart',
'fields' => 'id',
]);
$driveService->getClient()->setUseBatch(true);
try {
$batch = $driveService->createBatch();
$userPermission = new \Google_Service_Drive_Permission([
'type' => 'anyone',
'role' => 'reader',
]);
$request = $driveService->permissions->create($file->id, $userPermission, ['fields' => 'id']);
$batch->add($request, 'user');
$results = $batch->execute();
} catch (\Exception $e) {
} finally {
$driveService->getClient()->setUseBatch(false);
}
I noticed the data received from dd($googleDrive) is no data :
App\Components\GoogleClient {#3225
#client: Google\Client {#3203
-auth: null
-http: null
-cache: null
-token: null
-config: array:29 [
"application_name" => ""
"base_path" => "https://www.googleapis.com"
"client_id" => ""
"client_secret" => ""
"credentials" => null
"scopes" => null
"quota_project" => null
"redirect_uri" => null
"state" => null
"developer_key" => ""
"use_application_default_credentials" => false
"signing_key" => null
"signing_algorithm" => null
"subject" => null
"hd" => ""
"prompt" => ""
"openid.realm" => ""
"include_granted_scopes" => null
"login_hint" => ""
"request_visible_actions" => ""
I try to store it before the queue then the $drivegoogle data I get is as follows:
Google\Client {#3146
-auth: null
-http: null
-cache: null
-token: array:6 [
"access_token" => "*************************************************************************************"
"expires_in" => "*************************************************************************************"
"scope" => "*************************************************************************************"
"token_type" => "*************************************************************************************"
"created" => "*************************************************************************************"
"refresh_token" => "*************************************************************************************"
]
-config: array:29 [
"application_name" => ""
"base_path" => "https://www.googleapis.com"
"client_id" => "*************************************************************************************"
"client_secret" => "*************************************************************************************"
"credentials" => null
"scopes" => null
"quota_project" => null
"redirect_uri" => null
"state" => null
"developer_key" => ""
"use_application_default_credentials" => false
"signing_key" => null
"signing_algorithm" => null
"subject" => null
"hd" => ""
"prompt" => ""
"openid.realm" => ""
"include_granted_scopes" => null
"login_hint" => ""
"request_visible_actions" =>
is there any workaround to get the id from the storage::put method, or is there another way to fix my current error, the error appears at new \Google_Service_Drive($googleDrive); constructor must be array or instance of Google\Client {"exception":"[object] (TypeError(code: 0): constructor must be array or instance of Google\\Client
$googleDrive = $googleDrive->getClient()

How to mix $query->andFilterWhere and $query->query in Yii2 elasticsearch 6

I updated my yii2 system from yii2-elasticsearch 2.0 to 2.1 and elasticsearch package from 2.2.1 to 6.2.1. In the old system I could mix $query->andFilterWhere and $query->query as follows (the search method is in a class derived from yii\elasticsearch\ActiveRecord):
public function search($params)
{
$query = self::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
$query->andFilterWhere([
'languageCode' => \Yii::$app->locale->languageCode,
]);
$queryPart = [];
if (!empty($this->term)) {
$queryPart['filtered']['query']['multi_match'] = [
// ES6: $queryPart['bool']['must']['multi_match'] = [
'query' => $this->term,
'operator' => 'and',
'type' => $this->getQueryType($this->term),
'fields' => [
'name_*',
'meta_description_*'
]
];
}
if (!empty($queryPart)) {
$query->query($queryPart);
}
return $dataProvider;
}
It worked with ES 2.2.1 without any problem, but now the andFilterWhere overwrites $query->query independently from the sequence. If one of the two parts is removed the other filter works perfectly, only together not.
Any idea?
You must use bool query and put all part of your query in one "query" object...
Something like this:
query => [
bool => [
must => [
multi_match => [
'query' => $this->term,
'operator' => 'and',
'type' => $this->getQueryType($this->term),
'fields' => [
'name_*',
'meta_description_*'
]
]
]
filter => [
'languageCode' => \Yii::$app->locale->languageCode
]
]
]
This problem seems to be bug, as confirmed by other users on github.

Yii2: How do I get the database properties of model attributes?

How do you get the database column properties of the attributes of a model? Like datatype, default value, size, etc.
You can use $customer_model->getTableSchema() or Customer::getTableSchema()
Provides you with something like this:
yii\db\TableSchema#1 (
[schemaName] => null
[name] => 'customers'
[fullName] => 'customers'
[primaryKey] => [
0 => 'customerID'
]
[sequenceName] => ''
[foreignKeys] => [
0 => [
0 => 'orders'
'ord_customerID' => 'customerID'
]
]
[columns] => [
'customerID' => yii\db\ColumnSchema#2 (
[name] => 'customerID'
[allowNull] => false
[type] => 'integer'
[phpType] => 'integer'
[dbType] => 'int(10) unsigned'
[defaultValue] => null
[enumValues] => null
[size] => 10
[precision] => 10
[scale] => null
[isPrimaryKey] => true
[autoIncrement] => true
[unsigned] => true
[comment] => ''
)
...

Installing user-management for Yii2.0

I've been trying to install user-management for Yii2.0, but getting ReflectionException while loading the page. I have attached the error page and directory structure below.
and the file path is as shown below.
I've searched a lot to find out the reason for this, but nothing worked out. can someone tell me what am I missing here to get it work. looks like the user-management installation documentation has some flaws. It is not clear enough to understand. Hope to get the steps to install. Thanks
Here is my console/web.php
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'gAry7SfUr0oOjNQDqItsobmGBcJajQoW',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
//'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
'class' => 'app\webvimark\modules\user-management\components\UserConfig',
// Comment this if you don't want to record user logins
'on afterLogin' => function($event) {
\webvimark\modules\user-management\models\UserVisitLog::newVisitor($event->identity->id);
}
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => require(__DIR__ . '/db.php'),
],
'modules'=>[
'user-management' => [
'class' => 'webvimark\modules\user-management\UserManagementModule',
// 'enableRegistration' => true,
// Here you can set your handler to change layout for any controller or action
// Tip: you can use this event in any module
'on beforeAction'=>function(yii\base\ActionEvent $event) {
if ( $event->action->uniqueId == 'user-management/auth/login' )
{
$event->action->controller->layout = 'loginLayout.php';
};
},
],
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
];
}
return $config;
It seems to have a slight difference with the expected configuration for this extension.
Use this
'class' => 'webvimark\modules\UserManagement\components\UserConfig',
ie UserManagement instead of user-management is a configuration path and not a route

Hash with arrays - get array element

I get hash that contains user role, controller name and list of the controller actions this role can access to.
access = {
'admin' => [ 'users' => ['edit','delete'],
'messages' => ['show','update']
],
'user' => [ 'index' => ['index','sign-out'],
'messages' => ['show','index']
]
}
How can i check what access['admin']['users']['edit'] exists?
access['admin']['users'].include? 'edit'
However, this may be a problem: you're using ... => ['users'=>['edit','delete'],...]
This will create an array with a hash inside. Example:
{'a'=>'b'} #=> {"a"=>"b"}
['a'=>'b'] #=> [{"a"=>"b"}]
So consider using this:
access = {
'admin' => { 'users' => ['edit','delete'],
'messages' => ['show','update']
},
'user' => { 'index' => ['index','sign-out'],
'messages' => ['show','index']
}
}

Resources