I'm blocking on retrieving an item from a data list. My code:

<div id="contenu2" class="content">
<form action="" method="post" id="adminForm" name="adminForm">
    <table class="table table-striped table-hover">
            <th class="k2ui-center<?php if($context == "modalselector") echo ' k2ui-not-visible'; ?>"><input id="k2<?php echo $this->params->get('backendListToggler', 'TogglerStandard'); ?>" type="checkbox" name="toggle" value="" /></th>
                <th width="1%"><?php echo JHtml::_('grid.sort', 'ID', 'id', $this->sortDirection, $this->sortColumn); ?></th>
                <th width="2%"><?php echo JHtml::_('grid.sort', 'Name', 'name', $this->sortDirection, $this->sortColumn); ?></th>
                <th width="2%"><?php echo JHtml::_('grid.sort', 'Published', 'published', $this->sortDirection, $this->sortColumn); ?></th>
            <?php  if (!empty($this->items)) :  ?>
            <?php foreach ($this->items as $i => $row) : ?>
            <td class="k2ui-center<?php if($context == "modalselector") echo ' k2ui-not-visible'; ?>"><?php $row->checked_out = 0; echo @JHTML::_('grid.checkedout', $row, $key ); ?></td>
                <td align="center"><?php echo $row->id; ?></td>
                <td><?php echo $row->name; ?></td>
                <td align="center"><?php  echo JHtml::_('jgrid.published', $row->published, 'k2toflexi', true, 'cb'); ?></td>
            <?php endforeach; ?>
            <?php endif; ?>
                <td colspan="5"><?php echo $this->pagination->getListFooter(); ?></td>
    <input type="hidden" name="boxchecked" value="0" />
    <input type="hidden" name="filter_order" value="<?php echo $this->sortColumn; ?>" /> <!-- Todo: 404 composant introuvable -->
    <input type="hidden" name="filter_order_Dir" value="<?php echo $this->sortDirection; ?>" />
    <input type="hidden" name="task" value="" /> <!-- Probably useless -->
    <input type="hidden" name="boxchecked" value="0" />
    <?php if($context == "modalselector"): ?>
    <input type="hidden" name="context" value="modalselector" />
    <input type="hidden" name="tmpl" value="component" />
    <input type="hidden" name="fid" value="<?php echo JRequest::getCmd('fid'); ?>" />
    <input type="hidden" name="fname" value="<?php echo JRequest::getVar('fname'); ?>" />
    <input type="hidden" name="output" value="<?php echo JRequest::getCmd('output'); ?>" />
    <?php endif; ?>
    <?php echo JHTML::_('form.token'); ?>
    <input type="submit" name="tmpl" value="component" />

What I'm trying to do is get the line value if it is checked I found this line in several components:

<? Php $ row-> checked_out = 0; echo @JHTML :: _ ('grid.checkedout', $ row, $ key); ?>

But I didn't manage to get anything out of it! Do you have a direction to take? I'm a bit lost! Thank you in advance.

  • 1
    I don't understand what you mean by getting "the line value if it is checked" - could you explain this? The code you have with checked_out refers to displaying the little padlock symbol on the admin screen if the record is checked out in the database - see docs.joomla.org/J3.x:Developing_an_MVC_Component/…. Also you have 2 boxchecked fields - you should remove one of them. Please also give a bit of background - eg is this your own component which you have developed? Also, what are you seeing when you run this code? And what's wrong? – Robbie Jackson Mar 24 '20 at 19:08
  • Welcome to our community, @user14167 , please take our tour. Please respond to Robbie's feedback so that your question can be progressed. I recommend that you remove much of those unnecessary spaces in your script -- I don't know if <? Php causes trouble because I have only ever used <?php. – mickmackusa Mar 25 '20 at 0:08
  • Thank you for the welcoming @mickmackusa The spaces must come from a concern to copy paste, I do not know why they had this behavior it is well indented in my file ! – user14167 Mar 25 '20 at 8:35
  • @RobbieJackson Thank you for your answer, I'm not used to asking questions on the forums, I expressed myself badly! currently my component is handmade, it is a data migration component, I arrive with ajax requests to migrate all of my content, but I would like to refine my migration selection by selecting selection lines with checkboxes. Since yesterday I managed to get the corresponding ids using the variable $ _REQUEST ['cid] but I don't know how to pass this value on to my model in order to make the request that goes well. thank you in advance – user14167 Mar 25 '20 at 8:41

Yes, the ids of those records that have been checked will be sent in the HTTP POST request within a param array named cid. You can retrieve them via $_REQUEST['cid'], but it's safer to retrieve them by using the Joomla input functionality described in https://docs.joomla.org/Retrieving_request_data_using_JInput as that provides capability for filtering out data that could result in malicious injection attacks.

I would strongly recommend you read https://docs.joomla.org/Model-View-Controller and look at the Adding backend actions step of the Joomla MVC tutorial, as they'll provide a lot of background understanding for what you have to do.

When an administrator is presented with the form, selects a number of checkboxes and clicks on one of the buttons then the HTTP POST request will be sent containing:

  • the cid array set to the ids of the items which have been checked
  • the task parameter set to the action associated with the button.

You can experiment with the admin articles form with your browser devtools on to see this happening.

You define what the task parameter will be set to in your view.html.php file which displays a button using something like JToolbarHelper::checkin('articles.checkin'). So when you click several articles and click the Checkin button, the task parameter will be set to 'articles.checkin' and when the POST is received the server code will run the checkin() method within the administrator com_content controllers/articles.php.

This method is actually absent in this class, so instead it will run checkin() in the parent AdminController class. The first few lines of this method (in libraries/src/MVC/Controller/AdminController.php) are shown below:

public function checkin()

    $ids = $this->input->post->get('cid', array(), 'array');

    $model = $this->getModel();
    $return = $model->checkin($ids);

Here's an explanation of those lines:

$this->checkToken(); checks the token (preventing CSRF attacks) which is set by the line

<?php echo JHTML::_('form.token'); ?>

which you've quoted above.

$ids = $this->input->post->get('cid', array(), 'array');

gets the ids of the checked records from the HTTP POST cid array.

$model = $this->getModel();

gets a pointer to the model to use. You should define this method yourself in your controller php file, in the similar way to administrator/components/com_content/controllers/articles.php

$return = $model->checkin($ids);

this is where you call the method in the model to execute what you want to do, passing the ids of the checked records. You'll probably have to write this model function yourself to meet your own requirements.

I would recommend that you follow the Joomla paradigms in com_content etc as it makes your job much easier in the long run, even though there's a fair bit to assimilate at the outset.

  • Many thanks for the quality of your response, I will study all of this in detail and I hope to find my solution! Thank you – user14167 Mar 25 '20 at 14:47
  • Hello I advance slowly but I am again blocked. I manage to recover my value in my view with the Jinput of Joomla that you advised me I searched the doc of Jinput, but I do not find how transited this value in metod post or other to my model do you have a technique to use in this figure? thank you in advance – user14167 Mar 26 '20 at 9:57
  • 1
    I'm sorry @user14167 but this isn't really the place to find the help which it sounds like you need. I think you either need to spend the time going through the Joomla MVC development tutorial to get a thorough grasp of what's going on, or get someone close by who has a better understanding of Joomla, either from your own development organisation or by contracting a Joomla expert. – Robbie Jackson Mar 26 '20 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.