-
Inquisitor Newbie

-
Posts: 7
Threads: 2
Joined: Sep 2021
Reputation:
0
I've restored our old website from a very old backup but now the site won't load up and I'm getting php errors which I've never seen before. It's like menus.php file can't see $this->options->menu_items from main.php. If I create it inside menus.php then the error goes away but no errors are shown and I have no website.
Code Igniter version: 2.1.0.
PHP: 8.0.9
The only thing I can think of is that the site was originally ran on an older version of PHP which might have broken it. I've restored my database and altered the credentials in config/database.php.
It's been a long time since I did any coding so there's so much I can't remember.
If this is in the forum please move it, thanks.
Errors
Code: [b]Fatal error[/b]: Uncaught Error: Attempt to assign property "menu_items" on null in /home/seedeta1/public_html/application/libraries/menus.php:36 Stack trace: #0 /home/seedeta1/public_html/application/core/MY_Controller.php(9): require_once() #1 /home/seedeta1/public_html/application/controllers/main.php(8): MY_Controller->__construct() #2 /home/seedeta1/public_html/system/core/CodeIgniter.php(308): Main->__construct() #3 /home/seedeta1/public_html/index.php(202): require_once('/home/seedeta1/...') #4 {main} thrown in [b]/home/seedeta1/public_html/application/libraries/menus.php[/b] on line [b]36[/b]
Menus.php
PHP Code: <?php //Contruct menu bar. This is used in includes/header.php //Method = As in controller/method/id in CI urls.
/* Long term plan: Have a menus db table with all these in. Table will have name, uri (method), parent_id and level(1,2,3). * From here we can construct the menu using db queries. Grocery CRUD can then be used to manage that menus table. * The DB table may already exist but could need modification. */
$second_items=array( array('name'=>'Functional','method'=>'testing/functional'), array('name'=>'Performance','method'=>'testing/performance'), array('name'=>'Accessibility','method'=>'testing/accessibility'), array('name'=>'Usability','method'=>'testing/usability'), array('name'=>'Regression','method'=>'testing/regression'), array('name'=>'Compatibility','method'=>'testing/compatibility') );
$sub_items=array( array('name'=>'Testing','method'=>'testing','sub_items'=>$second_items), array('name'=>'Case Studies','method'=>'case_study'), );
$services_menu = array('name'=>'Services','controller'=>'services','sub_items'=>$sub_items);
$sub_items=array( array('name'=>'Tools','method'=>'tools'), array('name'=>'Cloud','method'=>'cloud'), array('name'=>'Blog','method'=>'blog') );
$technology_menu = array('name'=>'Technology','controller'=>'technology','sub_items'=>$sub_items);
$sub_items=array( array('name'=>'About','method'=>'about'), array('name'=>'Contact','method'=>'contact'), array('name'=>'Careers','method'=>'careers'), array('name'=>'Team','method'=>'team') ); $company_menu = array('name'=>'Company','controller'=>'company','sub_items'=>$sub_items);
$this->options->menu_items= array($services_menu,$technology_menu,$company_menu);
$bullet_class=''; $sub_bullet_class='';
Line 36 begins: $this->options->menu_items near the end of the file.
My_Controller:
PHP Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller { var $options; public function __construct() { parent::__construct(); require_once('application/libraries/menus.php'); date_default_timezone_set('Europe/London'); $this->options->page_title='Home page';
$this->options->company = $this->company_model->get_company_details(array('c_id'=>1));//Get company details such as address / telephone plus jquery slider options. }
/** * _not_selectable * * @access public * @param array values to print. * @return true. */
//Not selectable is useful when there are values in a select which cannot be selected as valid option. Second param is a piped string of primary key ids from the task_types db table. $option param = Value from select. function _not_selectable($option,$values) { if( ! isset($option) ) return true; $not_selectable = explode('|',$values); if(in_array($option,$not_selectable))//Is the value invalid? { $this->form_validation->set_message('_not_selectable', 'You selected an invalid option.'); return false; } return true; }
/** * _Valid_Date_Format * * @access public * @param array values to print. * @return true. */ //Check date format aggainst mysql format, valid dates only, no 30-2-2010. function _Valid_Date_Format($date) { if( empty($date)) return true; $converted=str_replace('/','-',$date);
if(preg_match("/^((((19|20)(([02468][048])|([13579][26]))-02-29))|((20[0-9][0-9])|(19[0-9][0-9]))-((((0[1-9])|(1[0-2]))-((0[1-9])|(1\d)|(2[0-8])))|((((0[13578])|(1[02]))-31)|(((0[1,3-9])|(1[0-2]))-(29|30)))))$/",$converted)===1) { return TRUE; }
$this->form_validation->set_message('_Valid_Date_Format', 'The Date entered is invalid.'); return FALSE; }
//Check that end date is after start date. function _check_start_end_date($start_date,$end_date) { if( empty($start_date)) return true; if(strtotime($end_date) > strtotime($start_date)) { return true; } $this->form_validation->set_message('_check_start_end_date', 'The start date must be before the end date.'); return false; }
//Callback function function _valid_email($userEmail) { if( empty($userEmail)) return true;
if($this->input->post('email')) { $user = $this->user_model->GetUsers(array('userEmail' => $userEmail));
if(isset($user->userEmail)) { $this->form_validation->set_message('_valid_email', 'Your email address is already taken.'); return false; } } return true;//true because no email = good result. }
//Callback to check username choice aggainst db. function _valid_username($userName) { if($this->input->post('username')) { $user = $this->user_model->GetUsers(array('userName' => $userName));
if(isset($user->userName)) { $this->form_validation->set_message('_valid_username', 'Your username is already taken, please choose another.'); return false; } } return true;//true because no email = good result. }
//Check that passwords match function _password_match($pass,$pass2) { if($pass==$this->input->post($pass2)) return true;
$this->form_validation->set_message('_password_match', 'The two passwords must match.'); return false; }
//Callback function function _check_login($userEmail) { if($this->input->post('password')) { $user = $this->user_model->get_users(array('userEmail' => $this->input->post('email'), 'userPassword' => $this->input->post('password')));
if($user) return true; }
$this->form_validation->set_message('_check_login', 'Your email / password combination is invalid.'); return false; }
function _check_email($userEmail) { if($this->input->post('email')) { $user = $this->user_model->get_users( array('userEmail' => $this->input->post('email') ));
if($user) return true; }
$this->form_validation->set_message('_check_email', 'The email entered does not exist in our database.'); return false; }
//Callback to check username choice aggainst db. function _is_financial($price) { if( empty($price)) return true;
if( preg_match("/^\d[\d\,\.]+$/",$price) === 1 ) { return TRUE; } $this->form_validation->set_message('_is_financial', 'Your price value is invalid.'); return FALSE; } /* * _project_user_allocation_check checks to see if there is already a link between a project and user. * If there is, return false. */ function _project_user_allocation_check( $p_id, $u_id ) { $pu = $this->project_users_model->get_project_users( array( 'u_id'=>$u_id, 'p_id'=>$p_id ) ); if( $pu['num_rows'] > 0 ): $this->form_validation->set_message('_project_user_allocation_check', 'There is already a link between that project and user. Change the user or project to continue or edit the existing project - user allocation.'); return FALSE; endif; return TRUE; } function email_sent() { $this->options->page_title='Email complete'; $this->options->meta_desc = 'Email complete'; $this->options->meta_keywords = 'Email complete'; $this->load->view('pages/email_sent.php',$this->options); }
function password_reset_complete() { $this->options->page_title='Password reset complete'; $this->options->meta_desc = 'Password reset complete'; $this->options->meta_keywords = 'Password reset complete'; $this->load->view('login/password_reset_view.php',$this->options); } }
/* End of file MY_controller.php */ /* Location: ./application/core/MY_controller.php */
Main.php:
PHP Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Main extends MY_Controller { var $options; public function __construct() { parent::__construct(); $this->options->page_title='Home page'; } //Functions inherited from core/MY_Controller function email_sent() {parent::email_sent();} function password_reset_complete() {parent::password_reset_complete();}
function index() { $this->load->model('post_model'); $this->load->model('images_model'); $this->options->images = $this->images_model->get_images(array( 'page_id'=>1 ));//Images for jquery slider, 1 for every feed. $this->options->pages = $this->page_model->get_page( array('uri_name'=>'homepage') ); $this->load->model('company_model'); $this->options->company = $this->company_model->get_company_details();//Images for jquery slider, 1 for every feed. //Load view. $this->load->view('main/main_view',$this->options); } }
/* End of file main.php */ /* Location: ./application/controllers/main.php */
|