Installing Add-on causes problem

Installing Add-on causes problem

by Maisam Abbas -
Number of replies: 5

Hi there. I am new to moodle. I have to complete a project. I am making my own block. I followed each step as discussed in doc.moodle.org/dev/Blocks.

When I click on 'upgrade moodle database now', it doesn't appear any information and a blank page appears, having address in browser like http://localhost/moodle/admin/index.php?confirmplugincheck=1&cache=0. Please help me in this matter. thanks in advance.

Average of ratings: -
In reply to Maisam Abbas

Re: Installing Add-on causes problem

by Valery Fremaux -
Picture of Plugin developers

Did you activate the debug mode ?

 

Average of ratings: Useful (1)
In reply to Valery Fremaux

Re: Installing Add-on causes problem

by Maisam Abbas -

Thanks Valery Fremaux for sharing information.

Actually I activated the debug mode too. This time blank screen didn't appear but an error occured which I think should not occur.

My code of config.php is here:

$CFG->dbtype = 'mysqli';
$CFG->dblibrary = 'native';
$CFG->dbhost = 'localhost';
$CFG->dbname = 'moodle';
$CFG->dbuser = 'moodleuser';
$CFG->dbpass = '1234';
$CFG->prefix = 'mdl_';
$CFG->dboptions = array (
'dbpersist' => 0,
'dbport' => '',
'dbsocket' => '',
);

$CFG->wwwroot = 'http://localhost/moodle';
$CFG->dataroot = '/var/moodledata';
$CFG->admin = 'admin';

$CFG->directorypermissions = 0777; //setting permission to edit
//something in config.php

//<--------below lines are used for displaying errors when blank pages appears or simply when 'dubugging on' needed-->
require_once(dirname(__FILE__) . '/lib/setup.php');

ini_set ('display_errors', 'on');
ini_set ('log_errors', 'on');
ini_set ('display_startup_errors', 'on');
ini_set ('error_reporting', E_ALL);
//<------------------------------------
//displaying more debuging messages
$CFG-> debug = 6143;
$CFG->debugdisplay = 1;
//<-------------------------------------

AND THE ERROR THAT OCCURED IS:

Parse error: syntax error, unexpected T_PUBLIC in /var/www/moodle/blocks/teachersnparents/block_teachersnparents.php on line 8 //error generated

 

What else do need to change in above code??

In reply to Maisam Abbas

Re: Installing Add-on causes problem

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

Where is the code for block_teachersnparents from? Can you post the first 20 lines of that block and say how many lines it contains in all?

In reply to Marcus Green

Re: Installing Add-on causes problem

by Maisam Abbas -

This is code for the block as mentioned in the 'making block step by step' documentation. I've only changed the name of my block i.e. block_teachersnparents.

<?php
class block_teachersnparents extends block_base {
    public function init() {
        $this->title = get_string('teachersnparents', 'block_teachersnparents');

// we need to display something in our block, therfore we need the following method

public function get_content() {   //this function defined here is an abstract function from content_base
    if ($this->content !== null) {
      return $this->content;
    }
 
    $this->content         =  new stdClass;
    $this->content->text   = 'Welcome to our first block \'TeachersnParents\'';
    $this->content->footer = 'Footer here...';
 
    return $this->content;
  }

// method for specilization
public function specialization() {
  if (!empty($this->config->title)) {
    $this->title = $this->config->title;
  } else {
    $this->config->title = 'Default title ...';
  }
 
  if (empty($this->config->text)) {
    $this->config->text = 'Default text ...';
  }    
}

} // the class END

// the PHP tag and the curly bracket for the class definition
// will only be closed after there is another function added in the
// next section

In reply to Maisam Abbas

Re: Installing Add-on causes problem

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

I suspect you have done more than that. You are trying to start the code for get_content before you have closed the block  for init, i.e. you are missing the closing } for init. I recommend you get a tool such as Netbeans which will highlight some errors before you load in a web server. See the attached image of your code (If you put your mouse over the red dot it gives an error message)

 

Attachment netbeans.png