I'm trying to create a custom Jtoolbar button in Joomla 2.5. I'd like the button to act very similar to the built in edit button, except I'd like it to be called generate. The button should load a generate view (similar to the singular edit view). It should have form fields for the user to fill out and then click a submit/save button that will run a php module to populate the database with calculated values.
My google searching has been very unproductive. So far I've been able to create the button with in games/view.html.php:
JToolBarHelper::custom('games.generate','extension', 'extension', 'generate', false);
I believe this should call a controller method in controller/games.php called generate().
in controller/games.php:
public function generate()
{
JRequest::setVar('view', 'schedule');
Jcontroller::display();
}
After much muddling around, this appears to be loading the view and a template tmpl/default.php. This seems wrong, but it's the furthest I've gotten so I'm going to keep going with it until I get it all figured out.
Original Question:
How do I get that controller to load the view/form/fields/template and then run the php script to populate the database. I probably just need a point in the right direction to figure this out. There doesn't seem to be any complete tutorials/examples on adding a custom button.
A couple of years old, and it's for 3.2, but I added this to my controller for a custom view. I needed a layout called insert. I don't know why you couldn't do the same to just change the view.
public function insert()
{
$this->setRedirect(JRoute::_('index.php?option=com_mycomponent&view=date&layout=insert', false));
}
Calling it the same way from a custom Jtoolbar button. It works, but maybe there is still a better way.
Related
I'm developing a component for Joomla! 3.x and I came across a strange issue. I followed the official documentation (http://docs.joomla.org/J3.2:Developing_a_MVC_Component/Adding_backend_actions) and I was able to get somewhere. Now the problem is that I wanted to expand the tutorial and create submenus within the components menu in the backend. I succeeded with this too.
The 2 submenu selections link correctly to 2 different views and I am able to fetch data from different tables nicely. The problem is that I cant add new entry to the database using my second view. The first view works fine. On the second view, when I click the green Add button, I get a jquery error: Uncaught TypeError: Cannot read property 'task' of null
The problem is that the addNew method cant find municipality.add or something. However this (almost) same code works for the default view.
What I'm trying to do is to display the data of 2 different tables in the DB and then being able to edit delete or add new.
Any ideas? Thanks in advance
The code
municipality.add
and
municipalitys.delete
refers to two different controllers, named municipality.php and municipalitys.php
You need to ensure the methods are present, in your case municipality.php should contain a
public function add()
which is not there. For a reference on how to implement it look at the other controller (most likely you'll invoke the add() method of the relevant model).
Or possibly you're extending the municipality controller from a different ancestor that doesn't implement the add method
Answering my own question, the problem was in the views/municipalitys/tmpl/default.php.
The form contained in that file was wrong, missing the id="adminForm" and the proper action= value.
I'm trying to figure out how to let the user add any numbers of tables or CGridview on a single page. So right now the page has two gridviews in it which will stay fixed. Now i want to add an add button somwhere, clicking on which will give the user another gridview, and so on.
How should i proceed with this. I mean is there an easy way to do this, without resorting to writing everything from scratch.
What i was thinking was to create a new view file using file_put_contents() or fwrite() dynamically everytime the user wants another table on the page? Now following in my line of thinking from where would i create these dynamically view files.
Should i write the whole code of the view and put it in a string, in the controller, and call file_put_contents() from there.
This would cause another problem as the filter needs a specific ajaxUpdate url like this
'ajaxUrl' => Yii::app()->createUrl('project/AjaxUpdate'),
.
Which would entail i would have also have to dynamically create the actionCode in the project controller for the filter in that dynamic grid to work. eg. project/AjaxUpdateDynamic1, project/AjaxUpdateDynamic2, etc.
So i'm kinda stuck with this problem. I would really appreciate if someone points me in the right direction.
Thanks, in advance,
Maxx
if you had an action for ajax loading your gridviews, you can then set your ajax url to that url and you'd have filtering possible for your model, you can even put multiple gridviews for multiple data providers that can be loaded via a parameter that you have sent along with click of your button and an input.
I have an action that renders search view to do search as the above search bar in this website, so its should be shown in every view.
I don't know what is the mechanism to do it. for example if I make the search action as a widget this will not be fine, because the results of search will be shown in the same position of the search widget ( at the top of website).
so, how I can make a search action that should be shown in every view in the website?
In order to resue same search function in everywhere, you need to create a widget.
I have explained briefly in How a widget works, then you can attach it in every view that you want.
If you don't have any idea to begin, check this out: Yii ESearch
Here are some references that would be useful:
how-to-use-a-widget-as-an-action-provider
actions-code-reuse-with-caction/
Yii Widget
If you want to add something to every view then you should add it to the layout. By the sounds of it you don't need to use a widget at all, although it would probably help with code maintainability.
You never mentioned a requirement for ajax so keep it simple and don't use it. When someone enters a search and clicks submit (or presses return) then the form submits to the SearchController. This way there is no need to have a search action in each controller.
If you particularly want the same action in every controller then create a Controller base class with that function in it and inherit from it to create all your other controllers.
Ok so i tried using zend form but what i'm trying to accomplish is way too much for me to handle zend form. I'll try to describe it in a few lines maybe you have a solution for me if not you will understand why i chose to use a form in a view file.
I have a form for searching products in a database. THe search is done using autocomplete (custom made). When the user presses "Add product to list" the product is being added to a div in the form, creating the impression of a list. I want to submit this (the newly added inputs in the form) to the controller and process the form. I don't know how to do this, or it is not possible, have no clue yet but the zend form gave me so many headaches that i am very close to stop using it.
So i have designed a static form, in my view file. I have my jquery stuff there, i add data (hidden input fields and checkboxes) and i want to post to my controller. The question is how do i get the $_POST array in my controller?
I'll try to answer you as better as I can givin how your question is vague.
If you have a html form on your webpage all you need to do is set its action to your controller:
action="mycontroller/myaction"
And in case its not:
method="post"
And in your controller in fact this would work:
$_POST['param_name']
but the Zend way would be in your controller's action:
if ($this->_request->isPost()) {
$data = $this->_request->getPost();
Zend_Debug::dump($data);
}
Hope this help. If you need more details edit your question to make ti more clear.
Also it does'nt matter if the form was created with Zend_Form or by hand that code will work regardless.
Hi I'm trying to use the CakePHP comments plugin found here http://cakedc.com/downloads/view/cakephp_comments_plugin but the instructions are really hard to follow. I've managed to add comments but it's displaying the commentWidget that's not working.
I'm getting confused at this part i think
To work properly, the component needs
a specific variable to be set in every
action using it. Its name should be
either
Inflector::variable(Controller::$modelClass)
or Comments::$viewVariable should be
set to other name of this view
variable. That variable should contain
single model record. for example you
need to have next line in you view
So far I've created the comments table, added it to the pluging and components arrays and added the following code to the controller:
public function beforeFilter() {
parent::beforeFilter();
$this->passedArgs['comment_view_type'] = 'flat';
}
I added the route
Router::connectNamed(array('comment', 'comment_view', 'comment_action));
And also the Comments.CommentWidget as a helper in my controller.
I'm just wondering if anyone has used this plugin before and can help me out?
thanks,
Jonesy
You're right - the documentation is really confusingly worded. However, if I understand correctly, what it wants is a copy of the record of the piece of data the comment will be attached to passed to the view the comments will render on.
So say you're making an event page, and you want people to comment on the event. You need to send to the view a variable called "event" with a copy of the base data for that event.
From their example they show: $this->set('post', $this->Post->read(null, $id));
For your event, you'd do something like $this->set('event', $this->Event->read(null, $id_of_event));
The Comment view probably needs this data for hidden fields so it can populate it with the model name and the event id.