I am using codeignietr pagination. I am facing a problem here.
The pagination numbers are coming in the page, but it is always fixed. Means if have total 8 pages, then I will click 5th page and it is going to the 5th page but from there if i click the next link it is not going to the 6th page, instead it is going to the 2nd page(the 1st page is always fixed or highlighted).
Currently If i click any page, only first page link only highlighting. I am expecting a code to highlight respective link on clicking on it.
Hello please set your $pagi_config['base_url'] correct.
Also please count correctly and set up $pagi_config['uri_segment'] correctly
in this particular case http://localhost/project_folder/articles //correctly set .htaccess + index.php removed is assumed
$pagi_config['base_url'] = base_url('articles/page'); //note that base_url() function is in url helper
$pagi_config['uri_segment'] = '3';
Please note that index() method in any controller does NOT accept any parameters! Anything written after controller name is considered as its method!
Also note that number generated by pagination library is not page number! It is offset!
Either use _remap(), or routes.php to make articles/<offset>, in routes case you still need extra method to take care of offset parameter.
On this part:
I am expecting a code to highlight respective link on clicking on it
Based on Codeigniter's docs, it should be something like this in your controller.
$config['num_tag_open'] = '<div class="current">';
$config['num_tag_close'] = '</div>';
You can than create a css style for .current and then whatever page you are on, the number will be styled.
Related
I have an view that extends the current project view, where we add multiple tabs (notebook pages) to show information from other parts of a project.
One of these pages is an overview page that summarizes what is under the other tabs, and I'd like to link the headlines for each section directly to each displayed page. I've currently solved this by using the index of each tab and calling bootstrap's .tab('show') method on the link within the tab:
$(".overview-link").click(function (e) {
e.preventDefault();
var sel = '.nav-tabs a:eq(' + $(this).data('tab-index') + ')';
$(sel).tab('show');
});
This works since I've attached a data-tab-index="<int>" to each header link in my widget code, but it's brittle - if someone adds a tab later, the current indices will be broken. Earlier I relied on the anchor on each tab, but that broke as well (and would probably break if a new notebook page were inserted as well).
Triggering a web client redirect / form link directly works, but I want to show a specific page in the view:
this.do_action({
type: 'ir.actions.act_window',
res_model: 'my.model.name',
res_id: 'my.object.id',
view_mode: 'form',
view_type: 'form',
views: [[false, 'form']],
target: 'current'
});
Is there any way to link / redirect the web client directly to a specific notebook page tab through the do_action method or similar on FormWidget?
If I understood well you want to select the tab from the JavaScript (jQuery) FormWidget taking into account that the id could change if anybody install another module that adds another tab
Solution 0
You can add a class to the page in the xml form view. You can use the id of the element selected by this class name in order to call the right anchor and select the right tab item. This should happen when the page is completely loaded:
<page class="nb_page_to_select">
$('a[href=#' + $('.nb_page_to_select').attr('id') + ']').click()
NOTE: As you have said the following paragrah I assume that you know where to run this instruction. The solution I suggest is independent of the index.
This works since I've attached a data-tab-index="<int>" to each
header link in my widget code, but it's brittle - if someone adds a
tab later, the current indices will be broken. Earlier I relied on the
anchor on each tab, but that broke as well (and would probably break
if a new notebook page were inserted as well).
Solution 1
When the page is loaded you can get the tab list DOM object like this:
var tablist = $('ul[role="tablist"]')
And then you can click on the specifict tab, selecing by the text inside the anchor. So you don't depend on the tab index:
tablist.find('a:contains("Other Information")').click()
I think if you have two tabs with the same text does not make any sense, so this should be sufficient.
Solution 2
Even if you want to be more specific you can add a class to the notebook to make sure you are in the correct notebook
<notebook class="nt_to_change">
Now you can use one of this expressions in order to select the tab list
var tablist = $('div.nt_to_change ul.nav-tabs[role="tablist"]')
// or
var tablist = $('div.nt_to_change ul[role="tablist"]')
Solution 3
If the contains selector doesn't convince you because it should be equal you can do this as well to compare and filter
tablist.find('a').filter(function() {
return $.trim($(this).text()) === "Other Information";
}).click();
Where "Other Information" is the string of the notebook page
I didn't tried the solution I'm giving to you, but if it doesn't work at least may be it makes you come up with some idea.
There's a parameter for XML elements named autofocus (for buttons and fields is default_focus and takes 1 or 0 as value). If you add autofocus="autofocus" to a page in XML, this page will be the displayed one when you open the view.
So, you can try to add this through JavaScript, when the user clicks on the respective link -which honestly, I don't know how to achieve that by now-. But you can add a distinctive context parameter to each link in XML, for example context="{'page_to_display': 'page x'}". When you click on the link, I hope these context keys will arrive to your JS method.
If not, you can also modify the fields_view_get method (here I wrote how to do that: Odoo - Hide button for specific user) to check if you get the context you've added to your links and add the autofocus parameter to the respective page.
As you said:
This works since I've attached a data-tab-index="" to each header
link in my widget code, but it's brittle - if someone adds a tab
later, the current indices will be broken.
I assume that your app allow multi-user interaction in realtime, so you have to integrate somewhere in your code, an update part function.
This function will trig if something has changed and cleanout the data to rebuilt the index in order to avoid that the current indices will be broken.
I am trying to create posts with comments with CodeIgniter and I am trying to add voting for the comments with + and -.
But my problem is not actually this functionallity but more exactly creating the link and the method in controller/model for this.
I understand that there is some kind of link to methods.
If I have something like this:
public function like() {
echo 'Test Function';
}
and when I create link like this one sitename.com/posts/first-post/like theoritecally I will see blank page with "Test Function" text (and of course if I write proper routing rule but I cannor for now).
I can see a blank page with this working echo 'Test Function', but does this mean I have to load every methods and views for the entire page if I want to display the entire webpage with all the elements? I think that I mistake something very serious here but I don't know what.
The example with the "Create news" tutorial in ellislab.com didnt help me. They show something similar I think with /create/ section in the URL and create() methods.
If I have many links with functionallities do I have to add new routing rules for all of them? I really tried to search in Google and everywhere but I didnt find anything related.
Sorry for this lame question.
You need to use Ajax call and on callback you have to increase or decrease the count. For creating a link , once page is loading render the data and provided the default link like
for + http://<site.com>/<controller>/like?totalLike=<36>
for - http://<site.com>/<controller>/unlike?totalunLike=<3>
Once user will click + link then by using Ajax, call the controller method link/unlike and increase or decrease the count and repopulate the link again with fresh counter.
Hope it will resolve your problem.
I'm building an image rating application, in which the main page is basically a grid of images with simple yes/no voting buttons at the bottom of each image.
I'm using Codeigniter for the server-side, Bootstrap (both CSS and JS) for the interface.
Now, I don't want to load all the images at once, but rather divide the images up to pages, wach page containing 10 images to reduce loading times.
I've been looking over the documentation # The CI Docs Which wants me to utilise a variation of this code:
$this->load->library('pagination');
$config['base_url'] = 'imgapp.com';
$config['total_rows'] = 100;
$config['per_page'] = 10;
$this->pagination->initialize($config);
echo $this->pagination->create_links();
Which Produces This:
The problem is, I haven't built it in a way that enables URI segments.
So, the links are quite useless - they are pointing to an adress of this sort:
http://www.imgapp.com/default_controller/3
Which is useless for me.
How do I configure the pagination to work with my image app?
Check http://ellislab.com/codeigniter/user-guide/libraries/pagination.html
The keys to configure pagination are:
$config['uri_segment'] = 3;
The pagination function automatically determines which segment of your URI contains the page number. If you need something different you can specify it.
$config['base_url'] = 'http://example.com/index.php/test/page/';
base_url This is the full URL to the controller class/function containing your pagination. In the example above, it is pointing to a controller called "Test" and a function called "page". Keep in mind that you can re-route your URI if you need a different structure.
I have a form which I dynamically build inside a jquery modal dialog.
var $myform = jQuery("<form id='EditForm' method='post' action='index.php?option=com_mycomponent&task=edit'></form>");
...
It gets processed by the edit method in my controller and then I redirect back to the desired page:
JFactory::getApplication()->redirect(JRoute::_('index.php?option=com_mycomponent'));
This submit from the form works and all is good except the url I get routed back to. It should be
index.php?option=com_mycomponent (or the SEF url)
but instead I get:
components/mycomponent/
Technically that is the same page but now it screws up any other operation I try to do after that. I'm guessing the fact that I create the form in javascript is part of the problem. I bet if I put
<?php echo JRoute::_('index.php?option=com_mycomponent') ?>
that might work. But I can't do that because this is a form in a separate javascript file where I don't have php available. Any ideas what I can do?
The URL you get is correct. It's the SEF URL for index.php?option=com_mycomponent.
You can add an Itemid (menu item) so the SEF URLs is prettier. Or you just can skip the JRoute part and you get the non SEF URL.
Update:
To get the currently active menu itemid you just get it from the current URL with either JRequest (depreceated) or JInput (http://docs.joomla.org/Retrieving_request_data_using_JInput):
$itemid = JFactory::getApplication()->input->get('Itemid', '0', 'INT');
But if there is an active menu item, JRoute should already add it itself.
Recently im working on a project and im trying to generate form elements with the help of ajax technology (implementing a form with codes). the situation is that the user should be able to select from a list of options and then due to his select another list of options should be appeared, then due to his/her select from the second sets of options he/she should see the third series of options. now the problem is that when the user tries to change the first option in the first set, the second option will be regenerate but the third one still sticks on the page. I was trying to use the form_sate['rebuild'] = TRUE
but it did not work and all form elements disappeared. can any one help me to see which code should be implemented and where it should be used?
Without any code it's almost impossible to help, except to say check out the examples modules, specifically the ajax_example module.
The basic principle is that you need a <div> container surrounding your 2nd and 3rd select elements, which will be replaced by the #ajax set on the first element. Then you need another container inside that one surrounding only the 3rd select element, which will be replaced by the #ajax set on the 2nd select element.
Hope that helps.
well.. the form page may contains previous values because of $_POST fields variables..
for example if I want to display clear "add" form on POST submit,
I do this tric to clear drupal previous form values via ajax:
<?php
// AJAX POST handler...
....
$my_form = drupal_render(drupal_get_form("the_form", ...));
$errors = form_get_errors();
if (!$errors) {
// re-render clean form, unset your POST fields....
unset($_POST['link_path']);
unset($_POST['link_title']);
unset($_POST['parent']);
unset($_POST['weight']);
$my_form = drupal_render(drupal_get_form("the_form", ...));
}
?>