Note that there are some explanatory texts on larger screens.

plurals
  1. POJoomla 2.5 creating component and saving data
    primarykey
    data
    text
    <p>I have been using this documentation (the only one I can find on the web) to build a component: <a href="http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5/Introduction" rel="nofollow">http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5/Introduction</a></p> <p>I can understand it to a certain extent, however it does really lack any definition. The component I have created works to a degree, though I am having some wier problems.</p> <p>Basically all I need the component to do is simply load a settings area to set a few values, and through it be able to change those values. Here is a breakdown of what I have:</p> <p>A view for a form, loading in form data from database. toolbars setup for save/apply and cancel.</p> <p>This loads with no errors, and according to all docs on joomla I have found, by initializing a JControllerForm instance with a JTable connected in the model, simple saving of forms should work automatically. However even though there is absolutely no reference anywhere in the code to a view with an s at the end (main view is tireapi, the forms always redirects to tireapis).</p> <p>This brings up a 500 error, as there is no place set that has that view. The documentation does include a list for a view, however I have only one row I need to edit, so a list is pointless. I know parameters can be set to components rather then making a database field, however I am unable to find any documentation relating to it.</p> <p>What I am looking for is direction on how to stop the component from redirecting to a none existent view, and properly save the data. Links to documentation that not only shows example code, but describes functions and how they work would be beneficial.</p> <p>Here is some of the code, feel free to point out anything I might be completely overlooking (I am newer to creating components):</p> <p>tireapi.php:</p> <pre><code>&lt;?php // No direct access to this file defined('_JEXEC') or die('Restricted access'); // import joomla controller library jimport('joomla.application.component.controller'); // Get an instance of the controller prefixed by TireAPI $controller = JController::getInstance('TireAPI'); // Get the task $jinput = JFactory::getApplication()-&gt;input; $task = $jinput-&gt;get('task', "", 'STR' ); // Perform the Request task $controller-&gt;execute($task); // Redirect if set by the controller $controller-&gt;redirect(); ?&gt; </code></pre> <p>controller.php:</p> <pre><code>&lt;?php // No direct access to this file defined('_JEXEC') or die('Restricted access'); // import Joomla controller library jimport('joomla.application.component.controller'); class TireAPIController extends JController{ function display($cachable = false){ // set default view if not set $input = JFactory::getApplication()-&gt;input; $input-&gt;set('view', $input-&gt;getCmd('view', 'TireAPI')); // call parent behavior parent::display($cachable); } } ?&gt; </code></pre> <p>controllers/tireapi.php:</p> <pre><code>&lt;?php // No direct access to this file defined('_JEXEC') or die('Restricted access'); // import Joomla controllerform library jimport('joomla.application.component.controllerform'); class TireAPIControllerTireAPI extends JControllerForm{} ?&gt; </code></pre> <p>models/tireapi.php:</p> <pre><code>&lt;?php // No direct access to this file defined('_JEXEC') or die('Restricted access'); // import the Joomla modellist library jimport('joomla.application.component.modeladmin'); class TireAPIModelTireAPI extends JModelAdmin{ protected $settings; //define settings public function getTable($type = 'TireAPI', $prefix = 'TireAPITable', $config = array()){ return JTable::getInstance($type, $prefix, $config); } public function getSettings(){ //grab settings from database if(!isset($this-&gt;settings)){ $table = $this-&gt;getTable(); $table-&gt;load(1); $this-&gt;settings = $table; } return $this-&gt;settings; } public function getForm($data = array(), $loadData = true){ // Get the form. $form = $this-&gt;loadForm('com_tireapi.tireapi', 'tireapi', array('control' =&gt; 'jform', 'load_data' =&gt; $loadData)); if (empty($form)){ return false; } return $form; } protected function loadFormData(){ // Check the session for previously entered form data. $data = JFactory::getApplication()-&gt;getUserState('com_tireapi.edit.tireapi.data', array()); if (empty($data)){ $data = $this-&gt;getSettings(); } return $data; } } ?&gt; </code></pre> <p>tables/tireapi.php:</p> <pre><code>&lt;?php // No direct access defined('_JEXEC') or die('Restricted access'); // import Joomla table library jimport('joomla.database.table'); class TireAPITableTireAPI extends JTable { function __construct( &amp;$db ) { parent::__construct('#__tireapi', 'id', $db); } } ?&gt; </code></pre> <p>views/tireapi/view.html.php:</p> <pre><code>&lt;?php // No direct access to this file defined('_JEXEC') or die('Restricted access'); // import Joomla view library jimport('joomla.application.component.view'); class TireAPIViewTireAPI extends JView{ function display($tpl = null){ $form = $this-&gt;get('Form'); $item = $this-&gt;get('Settings'); // Check for errors. if(count($errors = $this-&gt;get('Errors'))){ JError::raiseError(500, implode('&lt;br /&gt;', $errors)); return false; } // Assign data to the view $this-&gt;item = $item; $this-&gt;form = $form; $this-&gt;addToolBar(); // Display the template parent::display($tpl); } protected function addToolBar() { $input = JFactory::getApplication()-&gt;input; JToolBarHelper::title(JText::_('COM_TIREAPI_MANAGER_TIREAPIS')); JToolBarHelper::apply('tireapi.apply'); JToolBarHelper::save('tireapi.save'); JToolBarHelper::cancel('tireapi.cancel'); } } ?&gt; </code></pre> <p>views/tireapi/tmpl/default.php:</p> <pre><code>&lt;?php // No direct access to this file defined('_JEXEC') or die('Restricted Access'); // load tooltip behavior JHtml::_('behavior.tooltip'); ?&gt; &lt;form action="&lt;?php echo JRoute::_('index.php?option=com_tireapi&amp;layout=edit&amp;id='.(int) $this-&gt;item-&gt;id); ?&gt;" method="post" name="adminForm" id="tireapi-form"&gt; &lt;fieldset class="adminform"&gt; &lt;legend&gt;&lt;?php echo JText::_( 'COM_TIREAPI_DETAILS' ); ?&gt;&lt;/legend&gt; &lt;ul class="adminformlist"&gt; &lt;?php foreach($this-&gt;form-&gt;getFieldset() as $field): ?&gt; &lt;li&gt;&lt;?php echo $field-&gt;label;echo $field-&gt;input;?&gt;&lt;/li&gt; &lt;?php endforeach; ?&gt; &lt;/ul&gt; &lt;/fieldset&gt; &lt;div&gt; &lt;input type="hidden" name="task" value="tireapi.edit" /&gt; &lt;?php echo JHtml::_('form.token'); ?&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>These are all the files I can think of that may matter, let me know if I should include anymore.</p> <p>UPDATE: Now I can get the redirect problem to stop, however it will not save data. I get this error: You are not permitted to use that link to directly access that page (#1).</p> <p>This is the last hurdle to get this extremely basic admin feature to work. Any ideas? To clarify, I set the forms though an xml file and that loads properly, even filling them with the proper data from database. However when I click "apply" it just directs me back to the form with the error listed above, without saving.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload