Re: [jgen] registerTask don't work

88 views
Skip to first unread message

Michael Babker

unread,
Aug 8, 2012, 8:53:30 AM8/8/12
to joomla-de...@googlegroups.com
In your controller, try to do the registerTask call before invoking the parent __construct method.

From: chrisnorthstar <snup...@googlemail.com>
Reply-To: <joomla-de...@googlegroups.com>
Date: Wednesday, August 8, 2012 4:52 AM
To: <joomla-de...@googlegroups.com>
Subject: [jgen] registerTask don't work

Hallo,

I created a view controllers but registerTask don´t work.
The registerTask method seems to be  invoked  through out
 the construct method immediately and after the call of the $this->getTask() method
 it seems that nothing was happend after all. I really don´t get that.

Please help me.

How does it comes?

This is my Code of the component:

admin.test.php:

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport('joomla.filesystem.path');
jimport('joomla.application.component.controller');
$controllerClass = JRequest::getCmd('task', 'cpanel');
switch($task) {
    case 'cpanel':
        $controllerClass = 'cpanel';
        break;
    case 'posts':
        $controllerClass = 'posts';
        break;
    case 'comments':
        $controllerClass = 'comments';
        break;
    case 'addPost':
        $controllerClass = 'post';
        break;
    break;    
}
$pathControllers = JPATH_COMPONENT . DS . 'controllers' .DS. $controllerClass . '.php';
require_once $pathControllers;
$controller = $controllerClass . 'Controller';
$controller = new $controller();
$controller->execute(JRequest::getCmd($task));
$controller->redirect();

post.php:

<?php
defined('_JEXEC') or die ('Restricted access');
jimport('joomla.application.component.controller');

class PostController extends JController
{    
    function __construct($config = array()) {
        parent::__construct($config);
        $this->registerTask('addPost', 'newPost');
    }
   
    function newPost() {
        echo 'why this method isn´t invoked?';
    }
   
    function display() {
       $this->getTask(); //null
       parent::display();
    } 

the view:

defined('_JEXEC') or die ('Restricted access');
jimport('joomla.application.component.view');

class PostViewPost extends JView
{
    function display() {
        JToolBarHelper::title('A Test');
        JToolBarHelper::addNewX();
        parent::display();
    }
}
?>

--
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/-/AdIW0T_QJLUJ.
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.

chrisnorthstar

unread,
Aug 13, 2012, 7:28:11 AM8/13/12
to joomla-de...@googlegroups.com
Hello Micheal,

normally when i use php  I handle the errors this way:

This is the controller:

require_once 'model/buche.php';

switch($action)...

case 'buchen':
       $buchen = new Buche();
$errors = $buchen->getErrors();

       break;

include "view/$action" . ".php";

the errors are implement like this through the checkmethod

public function checkEnde() {
        if (!isset($this->ende) || $this->ende == "") {
            $this->errors = "Das Endefeld sollte ausgefüllt werden";
        }
    }
 
I display the errors in an view or work it it out in a helper.

My Problem with Joomla is:

I´ve got this code:

class TablePost extends JTable  {
   
        ...
        public $hits = 0;
         ...
               
    public function __construct( &$db ) ...
       
        public function check() {
            if ($this->title == '') {
            $this->setError(JText::_( 'Please subscribe the titel field' ));                    
        }
}

For example i want to the Error:$this->setError(JText::_( 'Please subscribe the titel field' ));
in the model to import it into the  view to display them and tell the users what they got to do.
At the Joomi api i read that the JTable->setError method is inherited from the Jobjectm but even when I call the jobject::getErrors();
Jobject errors is an empty array();

Do i have something missunderstood?

Kind regards
Chris
               

Am Sonntag, 12. August 2012 18:13:05 UTC+2 schrieb chrisnorthstar:
Thanks, It works now it seems that the task you want to register have to be the same as the executed task.
To unsubscribe from this group, send email to joomla-dev-general+unsub...@googlegroups.com.

Ove

unread,
Aug 13, 2012, 8:21:55 AM8/13/12
to joomla-de...@googlegroups.com, chrisnorthstar
Hi Chris,

I have a feeling that you are not following the Joomla MVC structure. Did you start by following the nice Joomla HelloWorld tutorial. There are a lot of conventions you have to follow. If you do, you have help from the Joomla Platform and the Joomla Cms. If you don't, you have to code everything yourself

e.g.  class TablePost extends JTable is not a correct naming and you can't display messages set by other methods in a view.html.php. The messages are automaticly displayed in your templates message position when loading the following page. Documented at http://docs.joomla.org/Display_error_messages_and_notices

You can also include messages in any redirect in the controllers.

(JError is deprecated in Joomla 3.0/12.1 so who do not use the copy/paste method could better use the enqueMessage method)

Regards
Ove
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/P7EbRLHxFKcJ.

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.

chrisnorthstar

unread,
Aug 13, 2012, 12:24:39 PM8/13/12
to joomla-de...@googlegroups.com
Yeah I know, the check method in the jtable is invoked automatically. Everything works just fine.

I thought i could use the same object where the error appears to display this error from this object anywhere in Joomla.
This is what i want to achieve:

view/tmlp/default.php

<form action="" ...>
<div="errorMessage">
<?php   -----I need the object within the data to display them-------  ?>
</div>
<form>

This is my TableClass:
I want to use the labeled code data in the view:

<?php

// Don't allow direct linking

defined( '_JEXEC' ) or die( 'Restricted access' );

class TablePost extends JTable  {
    /** @var int Primary key*/
    public $id = '';
        /** @var datetime */
        public $created_date_time = '';
        /** @var string */
        public $title = '';
        /** @var text*/
        public $items = '';
        /** @var int */
        public $checked_out = 0;
        /** @var datetime */
        public $checked_out_time = '';
        /** @var int */
        public $ordering = 0;
        /** @var tinyint */
        public $published = 0;
       
        public $hits = 0;
               
    public function __construct( &$db ) {
        parent::__construct( '#__ablog_posts', 'id', $db );               
    }
       
        public function check() {
            if ($this->title == '') {
            $this->setError(JText::_( 'Please subscribe the titel field' ));                    
        }
            if ($this->items == '') {
                        $this->setError(JText::_('Please subscribe the content field')); // In want to use this data in the view
                                                                                                                                                              
                       
        }
            return !$this->getErrors();
        }
}

Or do you have a better idea?

Kind Regards
Chris


Reply all
Reply to author
Forward
0 new messages