Hot answers tagged

12

The best practice is to create the addToolBar() method inside your View class and then using JToolBarHelper class to create command buttons: protected function addToolBar() { JToolBarHelper::addNew('yourcontroller.add'); JToolBarHelper::editList('yourcontroller.edit'); } So these will call the task/function "add"/"edit" in your specified controller. ...


11

In a proper MVC structure, only your controller should interface with your request data, in this case JInput, and the dependencies injected into the view and model when instantiated within the controller. With the current CMS structure, all three pieces of the MVC structure are often interfacing with the request data. In models, this is usually done in the ...


8

So far Google-searches make me presume that joomla caches your component automatically if you add display(true,...) to your controller's display method as in following example. The example also includes some measurement code to check if it's working (JProfiler part). public function display($cachable = false, $urlparams = array()) { $profiler = new ...


7

I think you're confusing the purpose of your main / master controller (controller.php) and subcontrollers (everything in the /controllers folder). For more on this, see the docs. The main controller is typically used to do what you mention in your comment (render a view based on the view parameter, usually specified in the URL). In controller.php, the ...


7

It is just a best practice used in many frameworks. The idea is to keep your HTML code in files which are as simple as possible (meaning almost no PHP code) so that they are easy to maintain / reuse. Let me explain: You basically use the JView (view.html.php) class which contains the data you want to display. This class has a display() method which will ...


7

Running ahead a little bit let me provide you with link to JooYii Library. This library makes a leap ahead brings some practices that would be at Joomla! 4 to current Joomla! 3.x branch along with other good things [common MVC, methods variables checks and bindings and other]. It's not reached first master yet, but only few inches around. What concerns ...


6

It's actually pretty simple. In view.html.php, load modal library, if it's not already done: JHtml::_('bootstrap.modal'); For adding button to toolbar, use: // Toolbar object $toolbar = JToolBar::getInstance('toolbar'); $layout = new JLayoutFile('joomla.toolbar.popup'); // Render the popup button $dhtml = $layout->render(array('name' => 'test', '...


5

You don't do $model->get('Locations'). The correct syntax is to just call the method name: $model->getLocations(). Using the ->get('Locations') syntax is only valid in a view (because get() is a method of the view class). This doesn't throw an error on the model, because it does also have a get method. However, it does a completely different task ...


5

In classes extending JView or JViewLegacy, a call to $this->get() will call a function in registered model classes starting with get. So calling $this->get('Item') will call a model's getItem method.


5

This question is impossible to answer conclusively, but I think that it is worthwhile to take a stab at some of the most common pieces that could trip you up in porting code over (and there will be quite a few). Before getting in to specifics, all of this could be considered a hack, depending on your point of view. The CMS and Framework are very different ...


5

You need to make sure the view that displays the buttons has a form to submit. The form name should be adminForm. The form should also have a hidden field named task and the dynamically generated token. I cannot recall the API off the top of my head, but something like JHtml::_('form.token'); (someone please correct this, if I'm mistaken) This do the ...


4

Currently, FOF is used for the postinstall messages and for the two factor authentication. Unfortunately the developer of FOF retracted his offer and is no longer contributing FOF to Joomla core. Thus using it as default is out of question and we in fact have to refactor the existing uses of it.


4

I would think you need to catch the output from your module using a component. You can use JForm to output the form in your module, and then have hidden inputs like <form action="index.php" method="POST" name="yourform"> <input type="hidden" value="com_yourcomponent" name="option"/> <input type="hidden" value="yourview" name="view"/> <...


4

A simple way to introduce a Ajax is with Joomla Ajax Interface:. What is The Joomla Ajax Interface (com_ajax) A slim, extensible component to act as an entry point for HTTP requests for stand alone modules and plugins, thus allowing for the potential of Ajax functionality in them. Com_ajax is generally used when you are not the developer of the component ...


4

Try using the postSaveHook method which allows the controller to access model data after it has been saved. public function postSaveHook($model, $validData) { $item = $model->getItem(); $my_new_group_id = $item->get('id'); }


4

Yes, You can simply include and instantiate your classes and interact with them the standalone PHP way you are used to - yes that is not a problem and Joomla doesn't restrict your ability to that - this approach gives you less to rewrite of your original code. However if you were up for a challenge, you could refactor your code classes - which are actually ...


4

Joomla is built on the MVC design pattern, so querying the db from a view is bad practice. But with your scenario, let's consider a few alteratives: changing the model: this makes no sense: you can't change a model you don't own, or you'll be tied to applying your changes with every new release; additionally, you mention it's overly complicated; query from ...


4

You can actually do it either way depending on which method you prefer. The way you are currently calling the functions in the view.html.php file is fairly common but you can also call those functions from within your layout (sub-view?) by including the model on that page. Layout 1 $model = JModelLegacy::getInstance('ViewName','ComponentNameModel'); $...


3

Let's say you have the category ID which is stored in $id. You can instantiate the category model as you did it before: $basePath = JPATH_ADMINISTRATOR . '/components/com_categories'; require_once $basePath . '/models/category.php'; $catModel = new CategoriesModelCategory(array('table_path' => $basePath . '/tables')); $id = 11; Now you have two methods: ...


3

Funny, I just finished yesterday the implementation of this plugin in a site. A fellow webdev and I modified it for joomla 3.x and it works. It's here : https://github.com/ghazal/plg_mvcoverride It throws an error though when coupled with a nonumber.nl extension, Advanced Module Manager: Call to undefined method JModuleHelper::addIncludePath() Being in ...


3

There is very little background on what else is in the component. You really need to check for database exceptions. See: How to do SQL exception / error handling compatible with 2.5 and 3.x? I see two options here: 1. Recommended You set up your debugger in your prefered IDE and look into the code to see what it does and where is the null coming from. ...


3

You're right the submit with a module is a bit more difficult because form submits have to go to a URL. It is messier to have to write a component just to accept the input from the module too. Because of this issue, in Joomla 3 is Matt Thomas wrote a component called com_ajax. Com_Ajax is a component that is designed to assist modules with doing things ...


3

To generate a list of tags you can take getTagTreeArray() method from JHelperTags class as a base and modify it for you needs - you can populate the resulting array not only with the IDs, but also with the tag names. Then on frontend you can use getTagRoute() method of TagsHelperRoute class to get the tag link. Hope this helps.


3

I would not use the controller - as controllers should be left to simply creating the model, view, linking them together and dealing with any redirect. As you say, the plugin way is going to produce additional overhead on all form's which doesn't make sense to me. So, my preference is the model, in its save() function. If you look at administrator/...


3

According to SQL theory, a 1:N relationship has to be represented by a table. In this model, any query can navigate the information in a consistent way. Forgetting the theory, you can store the relationship values into a field, for instance as a Json-encoded array. However, you are going to need someway to parse this "multivalued field" to manage it. In ...


3

I would really not recommend doing that. Joomla runs of relational databases (mySQL, postgre etc) which are optimised to handle relational tables. What you are describing is more in line with using a noSQL database (mongo, couchdb) which store documents that often consolidate hierarchical data. Joomla doesn't natively support such databases and as such I ...


3

In MVC the controller is responsible for getting the data from the request and passing it into the model. At the moment you are manipulating data from the request in your overwritten save method and then you call the parent save method (which will get fresh request data again). A better place for your modification would be the model. There is also a save ...


3

Your component's name is com_nautilus. With Joomla MVC your controller is looking for a class called "nautilusViewDatalist" in the file view.raw.php but you named your class "SimilarViewDatalist". That's were the error 500 comes from.


3

Legacy MVC will be supported until EOL of Joomla 3 (at least). I would just go ahead and use that. You will find many tutorials for legacy MVC and you will probably get the most help for that here or in the forums. Also (almost) all core components are developed with legacy MVC so you have many examples at hand. The new MVC is already usable but you will ...


Only top voted, non community-wiki answers of a minimum length are eligible