nourghoniem's avatar

Notice: Trying to get property of non-object

I'm trying to pass a variable from my controller to my view file. However, I get this error. Here's a sample from my Controller file

 if(empty($_REQUEST['SSN'])){

  $SSN_error= 'Please fill in the Social Security Number';
     // echo $form;
      die();
      }
      else{
        $SSN = $_REQUEST['SSN'];
        if(!preg_match("/^[0-9]{9}$/", $SSN)) {
         
         $SSN_error= 'Invalid SSN format';
        // echo $form;
         
         die();
        }
      }

and i'm trying to use the variable SSN_error (in a form) in my view file

        <div class="form-group col-md-6 col-sm-6">
                <label for="name"> National ID  </label>
                <input type="text" class="form-control input-sm" id="form-ssn" required="" name="SSN" placeholder=""></br>
                <p>'.$this->controller->insert()->SSN_error.'</p>
               </div>
0 likes
4 replies
tykus's avatar

What is $this->controller->insert() supposed to represent?

Can you properly format your code snippets so that they are legible?

Snapey's avatar

Please format your code by putting 3 backticks ``` on a line before and after each code block

Snapey's avatar

Are you actually using Laravel?

nourghoniem's avatar
<?php

abstract class  View{
    protected $model;
    protected $controller;

    public function __construct($controller, $model) {
        $this->controller = $controller;
        $this->model = $model;
    }
	
    public abstract function output();
}
?>

I can access functions in the model or the controller using $this->model or $this->controller. I want to pass a variable from a function named insert() in the controller to the view file

Please or to participate in this conversation.