SO confused about namespace & enquemessage...

557 views
Skip to first unread message

Troy Hall

unread,
Jan 25, 2019, 3:01:43 PM1/25/19
to joomla-dev-general
I've been trying to figure out this namespace stuff and can't find ANY docs explaining it.  I'm working in J! 3.9.x and working in phpstorm.
So, I'm trying to do a couple of things..
#1 check for valid parameter and if so, then check for valid folder or send error.


Notice JFactory is lined out?  If I remember right JFactory is deprecated, so what should be what?
here's the function call..


Now, here's the function file...

notice how only HTMLHelper is in white?
And finally here's the function....


Would you PLEASE explain to me what in the world I"m doing wrong, and how to NOT do it wrong next time?
Thanks in advance.
-- 
Troy Hall

Glenn Arkell

unread,
Jan 25, 2019, 4:47:26 PM1/25/19
to Joomla! General Development
Hi Troy,
I've been trying to learn about the namespace "stuff" for a wee while and this is what I've come up with.

Where ever there is a JSomething used, I gone hunting for a "Something" in the API listing (https://api.joomla.org/cms-3/namespaces/Joomla.html).  Generally I can find what I need.

Once I find the Something to replace I then add a "use Joomla\CMS\Something;" at the top of the file where I want to use it.  For example; in your first image you need to add "use Joomla\CMS\Factory;" and then drop the J from your statement to become $doc = Factory::getDocument();

Here is a list of the regular ones I use:

use Joomla\CMS\Component\Router\RouterBase;    //in the component router (site)
use Joomla\CMS\MVC\Controller\BaseController;  // in the component controller (site)

use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\MVC\Controller\AdminController;

use Joomla\CMS\Installer;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Factory;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\MVC\View\HtmlView;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\CMS\MVC\Model\FormModel;
use Joomla\CMS\MVC\Model\ItemModel;
use Joomla\CMS\MVC\Model\AdminModel;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin;
use Joomla\CMS\Plugin\CMSPlugin;  // extends CMSPlugin replaces JPlugin
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Form\Form;
use Joomla\CMS\Form\FormField;
use Joomla\CMS\Form\FormHelper;
use Joomla\CMS\Date\Date;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;
use Joomla\CMS\User\UserHelper;
use Joomla\CMS\Access\Access;
use Joomla\Data\DataObject;
use Joomla\Utilities\ArrayHelper;
use Joomla\Filesystem\File;
use Joomla\Filesystem\Folder;
use Joomla\Filesystem\Path;
use Joomla\Registry\Registry;
use Joomla\Event\Dispatcher;

If you have defined "use Joomla\Filesystem\Folder;" or "use Joomla\Filesystem\File;" then you don't need to jimport('joomla.filesystem.folder); etc.

I don't use phpstorm so there are some things in your code that I assume are placed there by phpstorm, but the way I use enqueueMessage is:

use Joomla\CMS\Factory;  // at the top of the file
Factory::getApplication()->enqueueMessage(Text::_('COM_MYCOMPONENT_ITEM_DELETED_SUCCESSFULLY'), 'success');

Now if someone notices anything I'm doing wrong in the above, then please say so, but I hope this helps.  Cheers.
Glenn

Michael Babker

unread,
Jan 25, 2019, 5:26:00 PM1/25/19
to joomla-de...@googlegroups.com
If you're working against a git clone of the CMS repo, run this script - https://github.com/joomla/joomla-cms/blob/staging/build/stubGenerator.php - that will generate a stubs file that most IDEs will pick up, basically it generates "stub" classes of all the old global namespaced classes that extend from the namespaced classes, with a doc block holding a deprecated tag.  You should be able to copy that in to a site if you're not working against a CMS clone.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send email to joomla-de...@googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/d/optout.

Rudolf Baláš

unread,
Jul 7, 2020, 5:20:19 AM7/7/20
to Joomla! General Development
Hi Michael,

i don't understand.

I put this file in root of my website on ftp and then run (call URL adress).
So then I see only white page and fole stub.php not generated (I tryied make on maximum Error Reporting too).

In which place I must put this file?

Thanks


Rudolf


Dne pátek 25. ledna 2019 v 23:26:00 UTC+1 uživatel michael...@gmail.com napsal:

sentix

unread,
Jul 7, 2020, 7:49:14 AM7/7/20
to Joomla! General Development
Hi Rudolf,
do you have a file classmap.php in joomla\libraries ?

If not, this file translates the J classes to the namespace ones.

regards
Manfred
Reply all
Reply to author
Forward
0 new messages