I am currently trying to perform pagination using CakePHP's pagination helper.
I have a series of "Listing" rows that are returned and paginated as expected. When the user clicks on the column headings however, I'd like the sort() method to be forced to prioritise certain listings (i.e. priority listings, those with ['Listing']['priority_flag'] = 1) first. However, when the user clicks on the column header, the browser url is set to
www.mysite.com/listing/index/page:1/sort:description/direction:asc
Hence, it is only sorting by description (as the user clicked on the column header for 'description'), ignoring anything to do with priority_flag.
All help appreciated!
gaioshin
I did this by writing an override paginate() function on the appropriate model. For the parameters, look carefully at the structure of the url you have pasted (you can modify it to suit your own ends, but then you would need to deviate from the pagination helper).
It's not difficult to do, but will require some thought. Look at the core to see how it works.
Related
I'm trying to create a Typo3 Extension using extbase and stumbled upon a problem.
What I have done so far is this:
I created a plugin editable via flexform for the backend. The plugin allows for dynamically changing some fields, so the flexform is using inline records that can be stored successfully in the database in their own table tx_jwfrontendusermanager_editorfields. The pid for the table entries is the same as for the content object they are attached to, and an additional field in the table holds the content object's id.
The backend works fine so far, I can create/edit/delete inline records for the content objects without any problem.
Unfortunately, I can't seem to figure out how to access the inline records in the ActionController in the frontend, and I can't find any documentation about how to do so. Could anyone point me into the right direction?
What I have tried so far:
First (primitive) approach: Accessing the flexform inline field like any other field from the form. This just returns the number "7". Obviously it's not meant to be used this way.
Second approach: I created a Model/Repository for the EditorFields table, and mapped the Model class to the table using Typoscript. The mapping itself seems to work fine. Unfortunately, I cannot select just the records that are connected to the current content object. A call to Repository->findAll() returns an empty array.
I debugged the SQL query for the findAll command and found out three problems:
The query filters by the tx_jwfrontendusermanager_editorfield.pid field, but using the wrong page id. The pid used is the one I selected in the plugin's 'Record Storage Page' field, not the one of the content object.
The query does not filter for the content object id, but would show all records for all content objects on the page.
The query filters by an additional
`tx_jwfrontendusermanager_editorfield`.`type` = "\Jw301\JwFrontendusermanager\Domain\Model\EditorField"
Which doesn't make any sense, as none of the records has the type field set to something like this. The type is used by the backend to distinguish between different kinds of records. That way, the query will never have any results.
So, how can this be changed in a way that the Repository finds the correct records? Is this even the right approach?
Third approach: As the Repository approach wasn't successful, I tried to get the records myself by creating a custom SQL query. This works in general, but I still have trouble filtering the right records for me.
I can get the current page id easily using
$GLOBALS['TSFE']->page['uid']
But there seems to be no way to get the content object id in the ActionController. I found many Internet sources that said I should use
$cObj = $this->configurationManager->getContentObject();
$cObj->data['uid']
from within the ActionController to access the current content object id, but for me that didn't work. I tried this in every ActionController in my project, yet the uid field was never there. The $cObj I get is of type ContentObjectRenderer, but the data array is always empty.
How can I access the content object uid from within an ActionController?
Thanks for any help or hints that lead me into the right direction.
I think I understand the concept of HMVC after reading this question and answer https://softwareengineering.stackexchange.com/questions/220480/hmvc-and-database-connections; an extract from an answer is below:
Let's assume you want to have a view that enables a user to make a
comment to a blog post. You would have fields for name, e-mail, title
and comment, but you also want to have a field country displayed as a
dropdown. In the action that displays this view you would make a
database query that loads the countries and then populate that
dropdown. Which is ok, but it forces you to duplicate the query and
the view required to display the countries if you need it in another
part of your application. A better approach would be to create
separate controller for countries with an action that returns a view
with the dropdown and then render that action whenever you need to
show a list of countries.
What I cannot wrap my head around is that if I can internally request a controller/model/view which just displays a widget (e.g. a country select box), doesn't that mean that by accessing that url from a browser will also just show that view?
How is this managed in HMVC, are routes defined as internal/external only, so matching an internal route with an external request would show a 404 page?
Is this generally how it is done and is the HMVC description/definition above satisfiable with the general use case of it in most web applications?
Showing the output of a sub-request in the browser shouldn't be a problem, so I wouldn't bother, especially that those URLs are not known by the user and it's safe to output the widgets separately.
Despite the above, you could, as #deceze mentionned, not attach those controllers to any routes. If you have a "default" route (matching all requests), then you would have to disable it.
I have a situation where I need to create a shortcut for a specific filter in a Joomla component.
The problem is that I cannot unset it, as I do not know if Joomla sets the form fields to its own session handler, request handler or some kind of custom handler. There also does not appear to be any documentation on this specific case.
The full situation is that I have a link that will auto filter in the same view as another link (in the components sidebar). One view will be just a specific filter and the other is standard. So I need it when you click into the filtered view it will reset the current filters to make sure everything displays as it should, and vice-versa so clicking back will again reset the filters.
I have tried a number of approaches for this, and although I can consistently force it to filter but it will not reset the form when I re-enter the last page with any technique I have tried so far and of course I want to avoid bypassing Joomla's default functions.
if(JRequest::getVar('filter_group_id',false)==10){
JRequest::setVar('last_filter',true);
EthicstoolHelper::addSubmenu('supervisors');
}else{
if(JRequest::getVar('last_filter',false)===true){
JRequest::setVar('last_filter',false);
JRequest::setVar('filter_group_id',false)
}
EthicstoolHelper::addSubmenu('users');
}
This is the most recent think I have tried, as you can see I try to reset the value to false in a hope that Joomla will read it as not being set, as JRequest has no built in unset method.
I don't have enough rep to comment yet, so I'm guessing a bit as to what the problem could be. Assuming that you are using a model to set the state of the filters, you can look at overriding the populateState method.
Another options is to fiddle with the context property in the model. For example, you could change the context if you have your special filters enabled if you are using things like $app->getUserStateFromRequest(). If you can post a bit more information about the design of your component (controllers and models), I can help more.
So I was writing a piece of functionality where I was getting the parent category ids of a category and wanted to get the url_key of one of the parents in Magento. I wanted to do this without having to load the category and found this method getAttributeRawValue, which can be found here /app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Abstract.php. Basically it seems unnecessary to load a whole entity then to just get the attribute value associated to that entity id.
It gets me what I need, but I am wondering if it is all that much better then loading the category and getting the attribute. Is loading the category essentially doing the same thing but doing it for every attribute?
My first thought would be to use the inbuilt Varien Profiler to test it quantitatively. It's an underutilized by very useful trick.
Basically, you need to turn on Profiling in the Admin (System>Config>Advanced>Developer>Debug>Profiler) and then insert the start/stop instructions with a unique string either side of the code that you want to profile. e.g.
Varien_Profiler::start('__CATEGORY_URL_KEY_RETURN__');
....
your code here
....
Varien_Profiler::stop('__CATEGORY_URL_KEY_RETURN__');
Load the page in your browser and you will see the Profiler output at the base.
Enjoy!
I have a link in my system as displayed above; 'viewauthorbooks.php?authorid=4' which works fine and generates a page displaying the books only associated with the particular author. However I am implementing another feature where the user can sort the columns (return date, book name etc) and I am using the ORDER BY SQL clause. I have this also working as required for other pages, which do not already have another query in the URI. But for this particular page there is already a paramter returned in the URL, and I am having difficulty in extending it.
When the user clicks on the a table column title I'm getting an error, and the original author ID is being lost!!
This is the URI link I am trying to use:
<th>Return Date</th>
This is so that the data can be sorted in order of Return Date. When I run this; the author ID gets lost for some reason, also I want to know if I am using correct layout to have 2 parameters run in the address? Thanks.
Yes, the layout is correct. Of course it's possible to have even more than 2 parameters in the query string
you have to check resulting query string (just take look into your address bar after click), there must be something like viewauthorbooks.php?authorid=22&orderby=returndate. If number is lost, you have to check it's source - $row['authorid'] variable.
you have to use & and sanitize your output, but apart from that it's correct ;)