PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 16, 2022

[FIXED] $this getting unknown property yii console

 February 16, 2022     php, yii, yii2     No comments   

Issue

I need to access a property of a class (which is a Yii2 Model), but when i refer to $this->expires_on inside a function of that class called with this code:

$int::createNextDate();

($int is a loaded yii model)

i get this error:

Exception 'yii\base\UnknownPropertyException' with message 'Getting unknown property: app\commands\DailyCronController::expires_on'

So basically php looks for the property inside the controller. How can i access that model's property instead?

Edit: here's the full code

this is part of the controller used by the command line

        $assistanceTasks = \app\models\AssistanceTask::find()->all();
        foreach($assistanceTasks as $task){
            $task::createNextDate();
        }

This is the function inside the model AssistanceTask

class AssistanceTask extends \yii\db\ActiveRecord{
...
public function createNextDate(){

    if(!$this->expires_on){
        return "Error....";
    }

But apparently there's a problem with "$this"

FINAL EDIT: The problem, as pointed by Patryk, is that i used

$int::createNextDate();

instead of

$int->createNextDate();

so the function was called as if it was a static function.


Solution

You are not trying to call expires_on not on Model but on DailyCronController



Answered By - user7242866
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing