-2

codes in both the files are deleted to make it concise and to the point :

controller/LessonMainController.php

use demo\Model\Courses\CourseToUser;
use demo\Model\Courses\CourseDependency;
use demo\Model\User;
use demo\Model\Course;

    if (!CourseDependency::isDependencyAccessible($_GET['course']) || !$this->course->isDateAccessible())
 {
   TemplateController::setMessage("This course does not exist or you are not allowed to access it");
   UrlhelperController::redirect(array('ctg' => 'start'));
  }

Model/Courses/CourseDependency.php

public static function isDependencyAccessible($course_id, $user_id = false) {
        self::checkId($course_id);
        if (!$user_id) {
            $user_id = User::getCurrentUser()->id;
        }
        $courses =  self::getDependencies($course_id);

        $access = true;
        if (!empty($courses)) {
            $user  = new User($user_id);
            $user_to_courses = CourseToUser::getAll(array('condition' => 'users_ID='.$user->id." and courses_ID IN (".implode(",", $courses).")"), array('courses_ID', 'status'));

            foreach ($user_to_courses as $value) {
                if ($value['status'] != CourseToUser::STATUS_COMPLETED) {
                     $access = false;
                }
            }
        }
        return $access;
    }

}

PROBELM:

In the absence of !CourseDependency::isDependencyAccessible($_GET['course']) everything works well but with this condition i get the error Using $this when not in object context (0) Please guide me to fix this.

prem
  • 241
  • 2
  • 11
  • You've provided zero useful details. Based on the single line error message you've provided there is absolutely no way to know where the error is happening. Please spend some time reading the [help] pages, in particular [ask] and [mcve]. You're asking us to speculate randomly about what's happening in a *project which is mvc structure and contains huge files*, and Stack Overflow is not a *throw wild guesses out and see which one sticks* site. Come back when you've spent some time trying to isolate the problem and have a specific question to ask, and we'll try to help. – Ken White Jan 06 '18 at 01:42
  • Read [Reference - What does this error mean in PHP?](https://stackoverflow.com/q/12769982/62576). Come back when you've made an effort. – Ken White Jan 06 '18 at 01:48
  • @KenWhite there you go found and lost few hairs. Please guide me now. – prem Jan 06 '18 at 04:34
  • Presumably the first script is not contained inside a method? – Rasclatt Jan 06 '18 at 04:57
  • Or if it is contained in a method, it may be contained inside a `static` method. – Rasclatt Jan 06 '18 at 05:03

1 Answers1

0

no quality help received and after hour of searching i solved it. Actually i was trying to call non static method inside static method. so i need to first convert that in to an object. If some one looking as how to do so :

 (new self)->checkId($course_id);
prem
  • 241
  • 2
  • 11