Can anyone tell the difference between find and findOne in yii2?

$this->_entity_model = $entity_class_name::find()->where(['service_request' => $this->id])->one();

Hello guys, could you please help me to figure out what’s happening heer ?

I have the record in DB but when ı execute this query I get
=>‘Invalid argument supplied for foreach()’

Not: I’m trying to switch to yii2 and I just changed my rules etc…

any help will be appreciated.


You can check debug toolbar and see what query statement outputs.
Else check of $this->id is set.
The code seems right.

It’s better to post some of the stacktrace and full error message. It usually points to exact place of the error and shows what caused it.

Hi @hyde82 and @samdark thanks for your answers, I have no stack trace neither the debug toolbar.
I did the config like explained =>
but ı still see the simple message without any stack trace which makes it very hard to upgrade to yi2

What does this means?
Enable Yii error reporting in index.php by change Yii debug on true.
Enable debug tool bar in you config file.


as you can see heer, there is no stack trace of the error, it’s hard to find where it comes from

// remove the following lines when in production mode
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
// specify how many levels of call stack should be shown in each log message
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', 4);

this is what i have in index.php
and in my config/web

     if (YII_ENV_DEV) {
     // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
    'class' => 'yii\debug\Module',
    // uncomment the following to add your IP if you are not connecting from localhost.
    //'allowedIPs' => ['', '::1'],

$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
    'class' => 'yii\gii\Module',
    // uncomment the following to add your IP if you are not connecting from localhost.
    //'allowedIPs' => ['', '::1'],


Uncomment allowed ip to enable debug

it stay similaire, I have uncommented the allowedIPS but stil get this error without stack trace
I added my public IP adresse, to make sur I added my local IP adresse too but no change

Could you show your index.php?

Maybe forget to change to dev-env?

Hello @demonking

use yii\web\Application;

$current_dir = dirname(FILE);

// change the following paths if necessary
define(‘DEFAULT_LANGUAGE’, ‘fr’);

define(‘ENVIRONMENT’, require(dirname(FILE) . ‘/protected/config/test.php’));

$config = dirname(FILE) . ‘/protected/config/’ . ENVIRONMENT . ‘.php’;

//Software Version
define(‘eRegistrations_Version’, ‘3.2.0’);

// remove the following lines when in production mode
defined(‘YII_DEBUG’) or define(‘YII_DEBUG’, true);
defined(‘YII_ENV’) or define(‘YII_ENV’, ‘dev’);
// specify how many levels of call stack should be shown in each log message
defined(‘YII_TRACE_LEVEL’) or define(‘YII_TRACE_LEVEL’, 4);

header(‘Content-Type: text/html; charset=utf-8’);
header(‘X-Frame-Options: SAMEORIGIN’);
header(“X-XSS-Protection: 1; mode=block”);
header(“x-content-type-options: nosniff”);
header(“Cache-Control: public”);
header(‘X-UA-Compatible: IE=Edge’);

require(dirname(FILE) . ‘/autoloaders.php’);
//require_once(dirname(FILE) . ‘/…/framework/yiilite.php’);

require(dirname(FILE) .’/protected/vendor/yiisoft/yii2/Yii.php’);
require(dirname(FILE) .’/protected/vendor/autoload.php’);

Yii::setAlias(’@root’, DIR);

$yii2Config = require dirname(FILE) . ‘/protected/config/web.php’;

try {
(new yii\web\Application($yii2Config))->run();
} catch (Exception $e) {
echo $e->getMessage();

Are you sure, the right config is loaded?


Are you testing on your local machine with docker or something else?

no it’s on server,

I’ve changed the environment to be web.php but still same no trace error

Like i see, YII_TRACE_LEVEL is only supported by yii1.x .

After grepping the Code from yii2, i haven’t found any clue of this constant.

thanks, deleted

But you could define a tracelevel in the Components Log part

 'components' => [
     'log' => [
         'traceLevel' => YII_DEBUG ? 5 : 0,

thanks, already done
@demonking @samdark

Guys, could you please help me to figure out this problem,
the screen is empty and I see only this error => ‘Invalid argument supplied for foreach()’
the debugger work well on other pages when I run a page called guide.php, which has

     $form->field($model, 'has_nationalite')->checkbox();
     $form->field($model, 'is_casier_judiciaire')->checkbox();
     $form->field($model, 'has_already_registered_if')->checkbox();

these tree checkbox ı get this error ‘Invalid argument supplied for foreach()’, When ı comment on these tree lines error goes.

any thing that I might be doing wrongly ? I’m trying to upgrade to yii2.

NOT: My model has two parent class when I remove all
public function rules from tree classes this error goes.

Error is likely logged. Check runtime/logs.

under the folder => runtime/logs/app.log
the last log record was a 10 of this month ?
I do not see anything else but old logs

OK. How about general PHP log?