Archived talk

Difference between revisions of "Developing a MVC Component/Adding configuration"

From Joomla! Documentation

 
(5 intermediate revisions by 3 users not shown)
Line 53: Line 53:
  
 
Does not influence the working. But is good to know when comparing your code. I use winmerge to compare my files with those in the zip file. Hoping to find that typo that prevents my version from running as it should ;-(
 
Does not influence the working. But is good to know when comparing your code. I use winmerge to compare my files with those in the zip file. Hoping to find that typo that prevents my version from running as it should ;-(
 +
 +
== Modifications that would make the tutorial clearer ==
 +
 +
I think the following 2 modifications would make this section of the tutorial clearer:
 +
 +
<ul>
 +
<li>Earlier in the tutorial, in the file site/models/helloworld.php $msg was used for the message, and here is is $item. I think it would be helpful to stay with the same variable name throughout the tutorial.</li>
 +
<li>In the file admin/tables/helloworld.php, the comment about deprecated code is confusing. It might be better if it read<br/>
 +
<blockquote>// loadJSON is @deprecated    12.1 (Joomla! 3)  Use loadString...</blockquote>
 +
so it is more obvious that the current code is correct for this version (2.5) but not the future version (3). Not everyone knows what the 12.1 is referring to and it looks like it is saying the code the tutorial is telling you to use is deprecated.</li>
 +
</ul>
 +
 +
== Changes to code created in previous articles ==
 +
 +
Reading through this entire series I have had a hard time determining what is added when a section of code is shown that says "add these lines to ''file_name''".
 +
 +
It would help to indicate the changes in some way (possibly highlighting).
 +
 +
[[User:Mazikowski|Mazikowski]] ([[User talk:Mazikowski|talk]]) 13:54, 9 July 2014 (CDT)
 +
 +
:Highlighting is available. So here would be an example and it's pretty flexible. e.g. highlight="13-21" or highlight="4,5,7-10"
 +
 +
<source lang="php" highlight="13-21">
 +
<?php
 +
// No direct access to this file
 +
defined('_JEXEC') or die('Restricted access');
 +
 +
// import Joomla view library
 +
jimport('joomla.application.component.view');
 +
 +
/**
 +
* HTML View class for the HelloWorld Component
 +
*/
 +
class HelloWorldViewHelloWorld extends JView
 +
{
 +
// Overwriting JView display method
 +
function display($tpl = null)
 +
{
 +
// Assign data to the view
 +
$this->msg = 'Hello World';
 +
 +
// Display the view
 +
parent::display($tpl);
 +
}
 +
}
 +
</source>
 +
 +
:Docs uses tags to initiate syntax highlighting.
 +
<pre>
 +
<source lang="php" highlight="13-21">
 +
...code in here
 +
</source>
 +
</pre>
 +
:I don't know if the writers of the series even realised this, plus some of the wording might indicate creating the entire code snippet in a blank file. It would be a great help if you wanted to update them, but I would suggest you start with 3.x version. 2.5 will reach EOL Dec of 2014. Thanks! [[User:Tom Hutchison|Tom Hutchison]] ([[User talk:Tom Hutchison|talk]]) 20:28, 10 July 2014 (CDT)

Latest revision as of 17:18, 26 April 2022

In the function

	/**
	 * Overloaded load function
	 *
	 * @param       int $pk primary key
	 * @param       boolean $reset reset data
	 * @return      boolean
	 * @see JTable:load
	 */
	public function load($pk = null, $reset = true) 
	{
		if (parent::load($pk, $reset)) 
		{
			// Convert the params field to a registry.
			$params = new JRegistry;                 
                       // loadJSON is @deprecated    12.1  Use loadString passing JSON as the format instead.
                       // $params->loadString($this->item->params, 'JSON');
//------------------------------------------------------------
                       $params->loadJSON($this->item->params);
//------------------------------------------------------------
 
			$this->params = $params;
			return true;
		}
		else
		{
			return false;
		}
	}

The line bracketed above is actually, $params->loadJSON($this->params); I am not sure which is 100% correct.

Just done a quick test and the one WITHOUT the 'item' is correct.



After changing files from 0.12 to 0.13 and downloading part13.zip I can't reach FrontEnd of HelloWorld component. I receive erorr 500. :( CodeBY 04:48, 4 May 2012 (CDT)

missing </fieldset> in admin\views\helloworld\tmpl\edit.php[edit]

It is not a critical error.

Looking at line 27 in the file admin\views\helloworld\tmpl\edit.php should look like this, as shown in the tutorial.

            </fieldset>

The file in the zipfile is missing this line </fieldset> (line 27)

Another minor detail is that the page on the website shows blocks of <?php ... ?> whereas the file as the php open and close per line.

Does not influence the working. But is good to know when comparing your code. I use winmerge to compare my files with those in the zip file. Hoping to find that typo that prevents my version from running as it should ;-(

Modifications that would make the tutorial clearer[edit]

I think the following 2 modifications would make this section of the tutorial clearer:

  • Earlier in the tutorial, in the file site/models/helloworld.php $msg was used for the message, and here is is $item. I think it would be helpful to stay with the same variable name throughout the tutorial.
  • In the file admin/tables/helloworld.php, the comment about deprecated code is confusing. It might be better if it read

    // loadJSON is @deprecated 12.1 (Joomla! 3) Use loadString...

    so it is more obvious that the current code is correct for this version (2.5) but not the future version (3). Not everyone knows what the 12.1 is referring to and it looks like it is saying the code the tutorial is telling you to use is deprecated.

Changes to code created in previous articles[edit]

Reading through this entire series I have had a hard time determining what is added when a section of code is shown that says "add these lines to file_name".

It would help to indicate the changes in some way (possibly highlighting).

Mazikowski (talk) 13:54, 9 July 2014 (CDT)

Highlighting is available. So here would be an example and it's pretty flexible. e.g. highlight="13-21" or highlight="4,5,7-10"
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

/**
 * HTML View class for the HelloWorld Component
 */
class HelloWorldViewHelloWorld extends JView
{
	// Overwriting JView display method
	function display($tpl = null) 
	{
		// Assign data to the view
		$this->msg = 'Hello World';

		// Display the view
		parent::display($tpl);
	}
}
Docs uses tags to initiate syntax highlighting.
<source lang="php" highlight="13-21">
...code in here
</source>
I don't know if the writers of the series even realised this, plus some of the wording might indicate creating the entire code snippet in a blank file. It would be a great help if you wanted to update them, but I would suggest you start with 3.x version. 2.5 will reach EOL Dec of 2014. Thanks! Tom Hutchison (talk) 20:28, 10 July 2014 (CDT)