Questions tagged [yii2]
Yii 2 is the latest version of the Yii framework - a high-performance, component-based PHP framework
15,349
questions
0
votes
1
answer
22
views
How to solve the problem of kartik datePicker with bootstrap4 in Yii2?
I installed yii2, (installed automatically yiisoft/yii2-bootstrap4), then installed kartik-v/yii2-widget-datepicker then this error comes out:
Invalid Configuration – yii\base\InvalidConfigException ...
-1
votes
1
answer
27
views
How to perform batch operations in YII Framework?
Now I'm working with a big project written on PHP + YII framework.
Now there is a task where it is required to import data from a big json-file into the database.
I'm afraid that this process would ...
0
votes
1
answer
25
views
Yii2 backticks cause error in activerecord query for JSON field
The following SQL query works fine:
mysql> SELECT `id`, `created`, `type`, `saved`->>"$.total" AS `total` FROM `invoices` LIMIT 20;
The saved field is in JSON datatype.
However, ...
0
votes
3
answers
43
views
In Yii2 i has passing model value but its showing as a null
There is my controller code
if ($this->request->isPost) {
$model->created_by = Yii::$app->user->identity->id;
$model->created_at = date('Y/m/d');
...
0
votes
1
answer
96
views
Yii2 PrettyUrl and ScriptName
here is what i did
in web.php
'request' => [
'parsers' => [
'application/json' => 'yii\web\JsonParser',
]
],
'urlManager' => [
'...
1
vote
2
answers
53
views
remove required from field in child model yii2
I have a main model and it has a field rules:
class User extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'users';
}
...
0
votes
1
answer
31
views
Trying to access array offset on value of type bool Yii2 PHP8.2
The following code produces the mentioned error.
What is the fix for PHP 8.2?
PHP Warning – yii\base\ErrorException
Trying to access array offset on value of type bool
In /var/www/html/atmtest/...
0
votes
1
answer
37
views
Yii2 apply validation rule on array of attributes
I use Yii2 and model rules for validation.
I have an $id attribute which is an hash value. The validation rule looks like this:
return [
['id', 'match', 'pattern' => '/^[a-f0-9]{16,32}$...
0
votes
1
answer
31
views
I'm using YII2, I'm displaying a list of inactive users. I'm using the checkbox to select the user. I'm going to send an email to the user I tagged
$user
id
name
001
user 1
002
User 2
<ul>
<?php foreach($user as $user( { ?>
<input class="is-selected" type="checkbox" value="<?= $value->user->...
0
votes
2
answers
47
views
Yii2 how to use Yii\web\session in console? ERROR session_set_cookie_params(): Session cookie parameters cannot be changed
I want to use the session in the console for use a function from model.
I use in the config from console the session like that:
main.php
main.php
...
return [
'id' => 'app-console',
'...
0
votes
1
answer
31
views
POST request with ReactJS fails with preflight OPTION status code = 404 with YII2 REST API
my frontend and backend is running on a nginx server which i have configure for proxy_pass, GET method is working fine but POST method was rejected because preflight request failed and preflight ...
0
votes
0
answers
26
views
How to configure nginx as development proxy to avoid CORS errors
for the past 3 days i've being searching the internet for solutions to CORS error to no success, i'm building a react app that access data from remote resource the remote resource is built with yii2 ...
0
votes
0
answers
42
views
Mpdf takes too much time to generate PDF
I'm using mPDF in Yii2 php framwork to generate the pdf as report.
getting the result as expected but it is taking too much time to generate the pdf-report (around 5-10 sec).
Pdf
This is the code for ...
0
votes
1
answer
42
views
Yii2 Mariadb transaction commits fine, but nothing gets stored in DB
I have a code:
$tx = Yii::$app->db->beginTransaction();
try {
// CODE (a lot of active-record reads and writes)
$tx->commit();
echo "All good!";
} catch (\Throwable $ex) {
$...
0
votes
1
answer
19
views
How to use PhpUnit mocking methods within codeception yii2 tests
I need to use PHPUnit mocking methods like expect($this->once())->returnSelf(); in codecept/yii2 tests. Cannot find any way to call them. The Stub library of codeception does not have as many ...
0
votes
0
answers
24
views
How yii2 handles multiple databases in console?
I have a Yii2 backend app with the following database schema (hundred of databases).
return [
'components' => [
'db1' => [
'class' => 'yii\db\Connection',
...
0
votes
0
answers
41
views
How to enable CORS in Nginx proxy server to allow react app access Yii2 rest API resource?
I'm building a react app which access api running on nginx server, in dev mode on local host i enable proxy by adding api server url to the proxy option in package.json file in react and everything ...
0
votes
0
answers
38
views
select2 not loading in bootstrap5 remote modal the first time. second time works
I recently moved from bootstrap3 to bootstrap5. Select2 in modal stopped working. I know there has been known issue in this which was resolved using
$.fn.modal.Constructor.prototype.enforceFocus = ...
1
vote
1
answer
38
views
Not able to Validation data in Yii2 model
I am not able to validate value in model. I am newbie in this can anyone suggest what am I doing wrong. I am working on REST API with excel file upload and validating single row at a time
Here is my ...
1
vote
1
answer
51
views
codeception doesn't builds helper files automatically
I have an YII2 application project with connected Codeception 4.1.8 testing framework (during the life of project before me there where made a lot of modifications).
So I tried to add my own method to ...
0
votes
1
answer
31
views
Yii2 PostgreSql how to add default value from another column on addColumn in migration
I have PostgreSQL DB table with 4 columns ex. col1, col2, col3, col4.
Col3 is unique indexed. I want to add new column with notNull and default value of col3 as after that I want to make newly created ...
0
votes
1
answer
39
views
Link pivot table in Yii2
I have one many to many relationship model. There are two tables user and entity. and I have created one another table user_entity to apply many-to-many relationship.
user.php
public function ...
0
votes
0
answers
40
views
Send event from php controller
Good morning everyone.
I need to send a notification whenever a user swipes a tab on a particular sensor.
The problem is not the connection to the sensor, which at this moment already takes place and ...
0
votes
0
answers
33
views
Yii2 translate a module from outside
If you have a yii2 module installed by composer how can you add a new language without touching the module itself (since touching anything in vendor/ is quite a bad practice)?
Let's say you have a ...
0
votes
0
answers
31
views
How do I build this query in yii2; myField like "firstname%lastname"
I have been using the Query builder in Yii2. When trying to make a filter like this:
where myaddress like 'avenue%12%espe'
When I tried this:
andWhere('like','myaddress', 'avenue%12%espe')
The ...
0
votes
0
answers
27
views
Yii2 popup when table update
Good morning everyone.
I am facing the following situation.
I have a management software written with Yii2.
This management software works with gyms and the following functionality was requested:
...
0
votes
0
answers
24
views
Yii2 pagination without pager
I'm trying to make a selection of records from the database by a certain number, for example, the first 5, when passing through the page number, get the other 5.
For example my current request:
/api/...
0
votes
1
answer
41
views
Yii2: Functional test running locally, fails on CI
I’ve set up testing for my app. The test suite runs fine locally, while it fails when executed via Gitlab CI.
Locally, whether I run:
./vendor/bin/codecept run functional ...
0
votes
0
answers
59
views
How can I import Vue component into application created in php file?
I'm included into some old project made in Yii2, which already consists hundreds of models and views.
I'm thinking about bringing some new breeze to it by adding Vue3 on top of existing platform.
I ...
0
votes
0
answers
23
views
how to get bandwith consumption in yii2 per request
How can I get the bandwidth consumption of user per request in yii2?
I tried afteraction and beforeaction in \yii\web\Controller but I don't get it.
0
votes
0
answers
46
views
Getting unsupported_operation_exception in elasticsearch when I use wildcard (*)
Below code was working in the elasticsearch 7.8 but it's throwing error after upgrade the elasticsearch server to 8.5. please have a look and let me know the solution.
{
"query": {
&...
0
votes
1
answer
23
views
return render doesn't work to retain data after reload
i want to retain data after submit if the data failed to validate. i use return render file input but this is doesn't work because the data still disappear. This is my code:
in my controller:
public ...
0
votes
2
answers
25
views
Yii2 transform 'string' datetime to int(11) datetime
yii2 have a function that transform something like '1671380485' to 'December 21, 2022'.
Yii::$app->formatter->asDate('1671380485', 'medium');
Do yii2 have a function that will make Reverse ...
0
votes
0
answers
35
views
Input validation error not showing to user
I have this in my action to validate an ajax post
if(Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())){
Yii::$app->response->format = Response::...
0
votes
0
answers
44
views
Ajax Progress bar interrupts page reloading(and flash-messages)(Ajax,Yii2,PHP)
The task was to create file uploading progres bar. (I'm a beginner,so please consider it). I found some good way how to make it with Ajax and JQuery. Everything seems to work good, percentege is ...
0
votes
0
answers
15
views
Yii2 Fileinput allow multiple screenshot insert
I have a Fileinput field and I want to insert there screenshots one by one, using print screen, but Fileinput remove previous file. What can I do ?
use kartik\widgets\FileInput
echo '<label class=...
1
vote
0
answers
27
views
How I can Display Multiple Images on DetailView in yii2
I have this code with images src array so i want to display all images from this array
<?php
$image = explode(',',$model->image_url);
?>
<?=
DetailView::widget([...
0
votes
0
answers
17
views
Update help-block of non-modified Yii2 ActiveFields with AJAX validation
There is a case in my Yii2 ActiveForm (validated with AJAX) where the validation result for a field X depends on the value of another field Y.
My intention is to have the validation error help-block ...
0
votes
1
answer
15
views
Can I use Yii2 classes to get the raw database table schema?
Can I use the Yii2 core classes to read the raw schema for a database table? So that I get the list of columns, types, lengths, etc?
Have tried looking at yii\db\mysql\Schema but can't figure out how ...
0
votes
1
answer
26
views
Fetch users data with related clients data in Yiii2 api
I need to get an API response, where each client row has its associated users' data in it. like this:
clients: [
{
id: 1
name: 'client_1',
users: [{ id: 1, name: 'user_1', ...
0
votes
0
answers
23
views
Yii2 Typeahead + table
I am new to Yii2 and I am trying to figure out how it works.
Now my scenario is that I have a controller which queries a DB and outputs a $table, that I use for the Typeahead Widget:
Typehead::widget([...
0
votes
1
answer
66
views
Yii2 GridView Filters behaving not working properly
Yii2 Gridiview filter not working properly. Selecting one filter have impact on other filters. Changing one filter (dropdown) auto-select the values of other filters (dropdowns). This problem also ...
0
votes
0
answers
32
views
Form data in view is lost or reset after modal popup
My form displays a dropdown list containing a list of statuses. When the selection changes a function is called thruough the dopdown list onchange property and the function calls up a modal. The ...
0
votes
1
answer
43
views
Can we remove some records from Active Data provider before passing to grid view?
I am facing issue with a scenario that I have to show data in two different grids present on same view. I don't want to query separately for both grids. What I want to achieve is to query only once ...
0
votes
2
answers
107
views
docker with php, nginx, redis, memcached connection refused 111
I have a project with Yii2 + nginx + php + redis + other services
What I want
so that each php, nginx, redis, etc... service located in a separate container
that does not work:
access to redis from ...
0
votes
0
answers
42
views
Trying to create a shopping cart in Yii2 and MySQL
I'm trying to create a functional shopping cart using Yii2 and MySQL but I'm kinda blocked right now
In MySQL i have two tabels: "Carrello" and "Prodotti". The first one should be ...
0
votes
0
answers
15
views
How to use yii2 joinWith aggregation (count, sum) query
I know use with query:
$customers = Customer::find()->with([
'country',
'orders' => function ($query) {
$query->andWhere(['status' => Order::STATUS_ACTIVE]);
},
])->...
0
votes
0
answers
25
views
Upgrade Yii 2 - no composer
I have no prior experience with Yii, and their documentation did not provide answers to my questions, so here we are:
I have a Yii2 project (2.0.42), which has been installed without composer. Can I ...
0
votes
1
answer
30
views
Yii2: How to filter multiple attributes using one filter attribute in DataFilter
Need help on filtering multiple attributes using only one filter attribute.
$filter = new ActiveDataFilter([
'searchModel' => static::class,
'attributeMap' => [
...
0
votes
0
answers
37
views
Why does this $year variable changes
I have code below, But why does this query builder passed the $year variable as :qp0?
$year = 2022;
$users = (new \yii\db\Query())->from('v_running_table')
->where(['...