Joomla 2.5.6 Component Development

998 views
Skip to first unread message

foysal foysal

unread,
Aug 10, 2012, 6:20:37 AM8/10/12
to joomla-de...@googlegroups.com
Can anyone say how the below button works??

JToolBarHelper::deleteList(JText::_('PERSONS_CONFIRM_DELETE'),'persons.delete');

I mean how this button send delete request to database ??


Thanks

Foysal

JSamir

unread,
Aug 10, 2012, 6:26:24 AM8/10/12
to joomla-de...@googlegroups.com
As far as i know, there is some JavaScript attached to this button which sets some hidden fields. Check it with firebug.

foysal foysal

unread,
Aug 10, 2012, 6:50:08 AM8/10/12
to joomla-de...@googlegroups.com
I know that delete method of persons class do the job. But I would like to know how this method get the id of the record ?? how the id pass to the method ??

thanks

Foysal

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/8UNPSccLtFQJ.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

Herman Peeren

unread,
Aug 10, 2012, 7:11:27 AM8/10/12
to joomla-de...@googlegroups.com
The checked checkboxes in front of the items are put in a hidden variable cid[ ]. This array contains the ids of the records.
 

MOHAMED AKRAM

unread,
Aug 10, 2012, 7:19:36 AM8/10/12
to joomla-de...@googlegroups.com
Hi, Foysal,
When you check the check boxes , and press the delete button, the task hidden field of the form is set to person.delete, where delete method in the person controller, there will be check box array is passed which name is cid, this id can be taken from the delete function in the person controller in the following way

$cid = JRequest::getVar('cid',array(),'','array');

now if you want to allow the user to delete multiple record then you can loop through the ids ($cid) array and delete record one by one,

else if you want to allow only delete one record, you can get the id value from the zero index of cid array
$id = $cid[0];


On Fri, Aug 10, 2012 at 4:41 PM, Herman Peeren <herman...@gmail.com> wrote:
The checked checkboxes in front of the items are put in a hidden variable cid[ ]. This array contains the ids of the records.
 

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/NznA5l0IvyoJ.

foysal foysal

unread,
Aug 11, 2012, 5:56:45 AM8/11/12
to joomla-de...@googlegroups.com
My delete button is not working. What can be the problem ??

Thanks

Foysal

foysal foysal

unread,
Aug 12, 2012, 2:54:38 AM8/12/12
to joomla-de...@googlegroups.com
Hi all,

I am learning  joomla 2.5 mvc component developing . But my delete button of admin panel is not working. What can be the cause ?? I searched a lot in google but could not get any soultion. Can anyone say where is the problem ??

Thanks 

Foysal

On Fri, Aug 10, 2012 at 5:19 PM, MOHAMED AKRAM <mohamed...@gmail.com> wrote:

Herman Peeren

unread,
Aug 12, 2012, 3:10:23 AM8/12/12
to joomla-de...@googlegroups.com
Hi Foysal,

Could you be a bit more specific: what happens and what not, under which circumstances? What have you done so far to test what happens? And maybe some code would be helpful too.

For now it is not clear to me what the problem is. I assume you have a MVC-component with a JTable and added a delete-button in the toolbar, but when you push that button nothing happens (that is: is the page not submitted at all? Or is it, but afterwards returns to the same page without the deletes being done?

Are you using the code in this tutorial?
http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5/Adding_backend_actions

Greetings,
Herman

foysal foysal

unread,
Aug 13, 2012, 11:32:11 AM8/13/12
to joomla-de...@googlegroups.com
Dear Herman,

Thanks for your valuable reply. I am new in joomla 2.5 component development that's why it is little more problematic for me to be specific.

I visited your link and some other tutorials then I am trying to develop a component using knowledge of those tutorials. But delete button of admin panel is not working.That means when I push that button nothing happens. 

Where can I start my checking ??

I am pasting some code for you.

in controllers folder

paper.php


<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controllerform library
jimport('joomla.application.component.controllerform');
class TestControllerPaper extends JControllerForm
{
}


papers.php


<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controlleradmin library
jimport('joomla.application.component.controlleradmin');
class TestControllerPapers extends JControllerAdmin
{
    /**
    * Set default values when no action is specified (ie for cancel)
    */
    public function getModel($name = 'Papers',
           $prefix = 'TestModel', $config = array())
    {
        return parent::getModel($name, $prefix, $config);
    }
}


in model folder

papers.php


<?php
defined('_JEXEC') or die();
jimport( 'joomla.application.component.modeladmin' );
class TestModelPapers extends JModelAdmin
{   
    public function getForm($data = array(), $loadData = true)
    {
    }
}


in tables folder

paper.php

<?php
// No direct access
defined('_JEXEC') or die('Restricted access');
class TablePaper extends JTable
{
    function __construct( &$db ) {
        parent::__construct('#__registry_persons', 'id', $db);
    }
}


here is my delete button code


JToolBarHelper::deleteList( JText::_( 'PAPERS_CONFIRM_DELETE'),'papers.delete');


some of my view code

default.php


<input type="hidden" name="task" value="" />

and


foreach($this->abc as $val)
        {
            $checked = JHTML::_('grid.id',$i++,$val->id);
            echo '<tr><td>'.$checked.'</td><td>'.$val->id.'</td><td>'.$val->name.'</td><td>'.$val->surname.'</td></tr>';
        }


Thanks

Foysal


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/fQOBB449xu0J.

Herman Peeren

unread,
Aug 13, 2012, 3:12:50 PM8/13/12
to joomla-de...@googlegroups.com
Thank you very much, Foysal. Unfortunately I don't immediately see an error in the code you showed. So: or I overlooked it or it is somewhere else.
Your question is where to start your checking.
I'd take the following steps:
  • look at the source code of the page with the delete button; FireBug can be of great help. Are all necessary ingredients there?
    - the checkboxes with something like <input type="checkbox" id="cb0" name="cid[]" value="3" onclick="Joomla.isChecked(this.checked);" and that value must be the id of your person
    - the javascript-libraries like mootools and <script src="/media/system/js/core.js" type="text/javascript"></script>
    - has the delete-button something like {Joomla.submitbutton('remove');} in the onclick attribute?
  • are there any error-messages? If something is wrong in Javascript, all further Javascript stops. You can find errors in Javascript in an Error Console of your browser (I use FireFox with all kinds of developer addons). You could also raise the error-reporting level of PHP to get PHP errors. In Joomla you can also put debugging on; then you can for instance see all db-queries.
  • and then the real debugging. In an IDE you could use XDebug, trace everything, set breakpoints etc., but that takes some time to get it in your fingers. But you can always do a simple "echo and die" debug to see if the program arrived somewhere and what the value of variables was at a particular point. Just echo values (or print_r for arrays or var_dump for whole objects). If a string is empty you won't see anything, so put something around that variable to see the spot where something should be printed. It can also be, that the program is redirected after your echo-statement; then you also would seen nothing. In that case: use die() to halt the program.

All 3 methods can be summarised as: looking "under water"; what is happening under the hood? Sometimes it takes longer, sometimes shorter, but you'll always find what is wrong. Debugging is an unseparable part of programming.

I'm curious what went wrong. Please let us know.

Ciao,

Herman

foysal foysal

unread,
Aug 15, 2012, 5:12:44 AM8/15/12
to joomla-de...@googlegroups.com
Thanks Herman, for your long valuable reply. I checked my code again and again found that I didn't write a line that is "<input type="hidden" name="boxchecked" value="0" />" .

But right now I am getting  following error

500 - An error has occurred.

View not found [name, type, prefix]: papers, html, testView

Return to Control Panel


I think joomla is looking for  TestViewPapers.

But why joomla looking for  TestViewPapers ??

Where did I mention to look for TestViewPapers ??


Thanks

Foysal



--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/tsP-9FSVf-EJ.

Herman Peeren

unread,
Aug 15, 2012, 7:59:52 AM8/15/12
to joomla-de...@googlegroups.com
On Wednesday, 15 August 2012 11:12:44 UTC+2, nowphp wrote:

View not found [name, type, prefix]: papers, html, testView

I think joomla is looking for  TestViewPapers.


But why joomla looking for  TestViewPapers ??
Where did I mention to look for TestViewPapers ??

Allright, we are almost there!

You are completely right that Joomla! looks for a class TestViewPapers here. You didn't have to mention it: it is looked for "automagically". This style of programming is called "Convention over Code" (CoC): as long as you follow the conventions, you don't have to write any code for it. If you want another name for your view, you'll have to put that in the code (i.c. with the controller's getView() method).

The advantage of CoC is that you have to write less code. The disadvantage is that you have to know the conventions. In this case: that if you don't specify the class name of the view, Joomla! will look for a class named [component_name]View[view_name] in the file view.html.php in the folder views/[view_name] of your component, where the view_name is the same as the model_name and the controller_name if not specified otherwise. In this case your component_name is "test" (without the com_) and your view_name is "papers". Another convention is that all file-paths are small case, but for  the class you use uppercase for the first character of the three pieces (so: TestViewPapers and not testviewpapers. Which would often not be a problem, for PHP is case sensitive, but not for class names. Still, you better get used to it to avoid some hard to find bugs).

There are frameworks that use the CoC-principle more widely than the Joomla!-platform. For instance Nooku Framework, which can be used besides the Joomla!-platform to make extensions for Joomla!. It will give you a 40 - 80 % code reduction; but because you first have to learn some conventions you also have a steeper learning curve (and you just experience the steepness of Joomla!'s learning curve right now). We have a Dutch football-player who is as well known for his way of saying things as for the way he played and he used to say: "every advantage has it's disadvantage" (or the other way around) and that is certainly true for Convention over Code!
Reply all
Reply to author
Forward
0 new messages