Welcome, Guest
Username: Password: Remember me

TOPIC: [SOLVED] Notices and Warnings

[SOLVED] Notices and Warnings 07 Oct 2011 01:12 #150

  • griiettner
  • griiettner's Avatar
  • Offline
  • Senior Member
  • Posts: 73
  • Thank you received: 12
  • Karma: 8
I'm finding many Notices and Warnings on the component.

I know that I could hide this by desabling the error on php.ini, but I don't like this aproach, so I rather clear all messages to have a nice writen code

So.. I'll be posting here some issues that I find and their solutions for those who likes to have clean code as well, and this can be used by the developers to fix those issues on futures releases

My first is related to a error that can be smilar to this:

Notice: Undefined property: stdClass::$params in ROOT\administrator\components\com_component_name\models\ticket.php on line 74

This is generated because the class $params was not initilized on model, so what you have to do is to find the function initData() and add the variable initilization, and it would be something like that
	function _initData()
	{
		if (empty($this->_data))
		{
			//Default values shown in the form for new item creation
			$data = new stdClass();

			$data->id = 0;
			$data->params = null;
			$data->variable1 = null;
			$data->variable2 = null;
			//Add the line below to your code
			$data->params = null;

			$this->_data = $data;

			return (boolean) $this->_data;
		}
		return true;
	}
As you can see, just add the $data->params = null; in your code and this warning will desapear..

For Admin, would be nice for this to be initialized on next release...

Thank you all.. more to come
Paulo Griiettner
Last Edit: 13 Oct 2011 17:07 by admin.
The administrator has disabled public write access.

Re: Notices and Warnings 07 Oct 2011 01:21 #151

  • griiettner
  • griiettner's Avatar
  • Offline
  • Senior Member
  • Posts: 73
  • Thank you received: 12
  • Karma: 8
The next is related to the publish function and you will see something like this:

Notice: Undefined index: publish in ROOT\administrator\components\com_app_name\models\model.php on line 148

What you have to do is just go to the file and line pointed on the error and do the following:

Substitute this:
if ($this->_active['publish'])	$where[] = "a.publish=1";
By this:
if (isset($this->_active['publish']) && $this->_active['publish'])	$where[] = "a.publish=1";

What happen here is that we are telling to the code see if the field check if the variable carry some data... case it not receive any data, it loads with empty.

Hope I was clear....

For admin, it would be good to generate the code with isset(), so it can get the code without the Notice...
Paulo Griiettner
Last Edit: 07 Oct 2011 01:25 by griiettner.
The administrator has disabled public write access.

Re: Notices and Warnings 07 Oct 2011 01:41 #152

  • griiettner
  • griiettner's Avatar
  • Offline
  • Senior Member
  • Posts: 73
  • Thank you received: 12
  • Karma: 8
Now we will take care of a deprecated function on PHP5, the famous eregi... so if you get an Warning such as

Deprecated: Function eregi() is deprecated in ROOT\administrator\components\com_app_name\dom\dom.php on line 453

You will have to substitute this?
if (eregi("\[([A-Z0-9_]+)\]", $text))
To this?
if (preg_match("/\[([A-Z0-9_]+)\]/", $text))
For admin, I not sure the impact this change would have in whole application, since, changing this, would implicate on no support for PHP4 servers
Paulo Griiettner
The administrator has disabled public write access.

Re: Notices and Warnings 07 Oct 2011 03:27 #153

  • griiettner
  • griiettner's Avatar
  • Offline
  • Senior Member
  • Posts: 73
  • Thank you received: 12
  • Karma: 8
On the dom folder, j-cook has it's own class to generate fields such as select, radio, checkbos and etc...

But has some warnings as well... if generating a select with <opgroup> tag, you will probably get the following Notices:

Notice: Undefined index: state in ROOT\administrator\components\com_app_name\dom\html\form\input\select.php on line 171

Notice: Undefined index: state in ROOT\administrator\components\com_app_name\dom\html\form\input\select.php on line 173

Notice: Undefined index: state in ROOT\administrator\components\com_app_name\dom\html\form\input\select.php on line 185

What you have to do is substitute the following, around line 166
foreach($this->list as $item)
		{
			// Close OPTGROUP
			foreach(array_reverse($groupBy) as $groupKey => $groupLabelKey)
			{
				if ($group[$groupKey] != $item->$groupKey)
				{
					if ($group[$groupKey] != null)
					{
						$indent --;
						$html .= $this->indent('</optgroup>', $indent) .LN;
					}

				}
			}

			// Open OPTGROUP
			foreach($groupBy as $groupKey => $groupLabelKey)
			{
				if ($group[$groupKey] != $item->$groupKey)
				{

					$prefixGroup = str_repeat($indentStrGroup, $indent);

					$html .= $this->indent(
							'<optgroup label="'
							. $prefixGroup . htmlspecialchars($item->$groupLabelKey, ENT_COMPAT, 'UTF-8')
							. '">' .LN
							, $indent);

					$indent ++;
					$group[$groupKey] = $item->$groupKey;

				}
			}

By the following code:
foreach($this->list as $item)
		{
			// Close OPTGROUP
			foreach(array_reverse($groupBy) as $groupKey => $groupLabelKey)
			{
				if (isset($group[$groupKey]) && $group[$groupKey] != $item->$groupKey)
				{
					if ($group[$groupKey] != null)
					{
						$indent --;
						$html .= $this->indent('</optgroup>', $indent) .LN;
					}

				}
			}

			// Open OPTGROUP
			foreach($groupBy as $groupKey => $groupLabelKey)
			{
				if (!isset($group[$groupKey]) || $group[$groupKey] != $item->$groupKey)
				{

					$prefixGroup = str_repeat($indentStrGroup, $indent);

					$html .= $this->indent(
							'<optgroup label="'
							. $prefixGroup . htmlspecialchars($item->$groupLabelKey, ENT_COMPAT, 'UTF-8')
							. '">' .LN
							, $indent);

					$indent ++;
					$group[$groupKey] = $item->$groupKey;

				}
			}

This will heal the wounds... :P
Paulo Griiettner
The administrator has disabled public write access.
The following user(s) said Thank You: admin

Re: Notices and Warnings 07 Oct 2011 11:55 #156

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Lots of Thanks griiettner,

I consider this is very important.

Priority N°1.

Karma +1
Coding is now a piece of cake
Last Edit: 07 Oct 2011 12:07 by admin.
The administrator has disabled public write access.

Re: Notices and Warnings 13 Oct 2011 17:06 #223

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Cleaned since 1.3.2
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: griiettner

Re: [SOLVED] Notices and Warnings 13 Oct 2011 18:09 #227

  • griiettner
  • griiettner's Avatar
  • Offline
  • Senior Member
  • Posts: 73
  • Thank you received: 12
  • Karma: 8
Perfect man... thank you very much...
Paulo Griiettner
The administrator has disabled public write access.
Time to create page: 0.101 seconds

Get Started