Cakephp Pagination URL - cakephp

I am facing a problem in cake php pagination. In my project I have Category Suppose 'Wooden' , In this I have Sub Category as 'Wooden Tables' and further 'Wooden tables' has many products. In sub category i am doing pagination . I am showing 10 items per page. Now the problem is that When i click on any of the pagination link , its missing sub category number. for example : the URL should look like this : http://amazingtech.in/lariya/products/index/4/page:2 but when i click on pagination link the URL look like this http://amazingtech.in/lariya/products/index/page:2 . It is missing the sub category number 4 , which leads to page not found error. and when i manually enter the URL Like this . It works.
I don't know how to modify pagination URL. Thanks in advance.

Pagination - that is selecting or sorting results - isn't the same as searching for them by criteria, even though Cake supports passing them as an array or named params. That is to say, conditions of your find() are not preserved in the same way as your pagination params.
So You'd need to include your condition as a named or query parameter: eg: assuming your category is 'category' (it might be category_id, replace as needed)
http://amazingtech.in/lariya/products/index/category:1234/page:2
Or possibly:
http://amazingtech.in/lariya/products/index/category:Wooden/page:2 //more SEO friendly
Or even:
http://amazingtech.in/lariya/products/index/4/page:2
http://amazingtech.in/lariya/products/index/Wooden/page:2 //more SEO friendly
To do it this last way you'll need to setup your controller to look for the first URL param in and assign it as a condition of your find() operation:
public function index($category = null) {
$conditions = array('Products.category_id' => $category);
...etc
}
MORE: CakePHP Cookbook Parameters
That way, when you paginate - as long as you're going through the same controller - can preserve that category.

Related

Display data in lwc datatable as pdf

I want to display data as pdf that is in my lightning datatable in lwc. These list i am getting from api response . It can range from 10 to 2000 or even more.
So I tried below method to pass data to VF page
Approach 1 :
Passing list as string parameter to VF page URL , but that is hitting my URL limit.
Approach 2:
Declared get set variable in lwc controller and assigning values on click on print button, but that print blank pdf page .
Approach1:
LWC apex controller
Pagereference pageRef = new PageReference('/apex/Locations');
pageRef.getParameters().put('locations',locWrapList);
pageRef.getParameters().put('brandName',brandName);
It is giving URL limit error
Approach 2:
lisOfLocation= (List<LocationWrapper>)JSON.deserialize(locWrapList, List<LocationWrapper>.class);
I am using this lisOfLocation in VF page , but on click of print it is printing blank
Is there any way I can handle this.

AFC Repeater and wp-rest api in React.js

Need to render ACF repeater in react. I am able to display ACF text Fields but not repeater fields. Need to find out if anyone has an example of how to map through a repeater field.
Repeater field group Is called Skills.
Im also new in this stuff, but I will try to help you.
So, the first thing that you need is to download and install ACF to REST API plugin so you can use ACF with Wordpress API. I assume, that you already have it, because as you said before - you can display text fields.
Once you can send data through Wordpress API, you need to preview of JSON sent by Wordpress (in this case), so you can display necessary data. Mine is called React Developer Tools and I installed it as Chrome extension.
Link to Chrome store
It should look like this:
As you can see, my component is called Home.js, yours may be called differently. Chose component that is fetching all the data that you need.
Now, you just need to use your repeater. It would be much easier if you showed us your code. I don't really know what kind of data you are calling through api, so I guess these are pages.
{ pages[0].acf.technologie_lista.map ( (field, index) => (
<div key={index} className="single-field">
{ field.nazwa_technologii }
</div>
) ) }
Let's break it down.
1 - My project contains two pages. I have chosen the first one, because only this one has needed ACF fields. technologie_lista is acf field name.
2 - You need to use map function to list all posts. You need to assign key to each element.
nazwa_technologii is just a repeater sub field name.
And that's all. I might make some rookie mistakes, but it work's for me. I hope that i helped. Cheers!

Oxygen - Advanced Custom Fields Repeater sub-fields - link fields

WordPress Repeater link fields: For testing purposes I have defined one link as an Array and the second link as URL. When adding the repeater to a template the output of one link is an Array and the other link is displayed as URL instead of the actual "link text". The link also doesn't open link in new tab as defined.
What's wrong with this setup? See attachments
Working solution to the problem described above:
It is important to know that my issue with ACF and Repeater is related to the Wordpress Oxygen builder.
In order to get get link fields with target blank you need to do the following:
CPT UI > create post type (set has Archive = true)
Custom Fields > Add field type Repeater, add sub-fields = field type set to text
Posts > Add Rows with link custom fields
Create Template > Add repeater to page, add text link module, set data to appropriate Field Name
Define link target: Add JS code block and add the following code
jQuery('a').each(function() {
var a = new RegExp('/' + window.location.host + '/');
if (!a.test(this.href)) {
jQuery(this).attr("target","_blank");
}
});

Filter articles in blog category by article id in Joomla 3

In category.php model, there is a bunch of $model->setState filters, that shapes the output of articles.
I am trying to add new setState, that will filter output of articles by given id's
$model->setState('filter.id', $params->get('id_articles', array());
but still wont filter. So i tried with direct id input:
$model->setState('filter.id', '280');
and still, the output is not filtered at all.
To be sure if this kind of filter works, i modified the model->setState for featured articles:
$model->setState('filter.featured', 'only');
and this proves that $model->setState works properly, but it won't accept filtering by article id.
Any ideas? Thanks!
in your populateState() method set the state to :
$articleIds = explode(',', $params->get('id_articles'));
$this->setState('filter.article_id', $articleIds);
$this->setState('filter.article_id', $articleIds);
then in your getItems() method just set the state in the model to:
$model->setState('filter.article_id', $this->getState('filter.article_id'));
and you'll get the desired result.

ajax pagination in cakephp , can't know how to use it

how to use ajax pagination in cakephp .I'm also using search the database by the keywords also.. data only matches with keyword shoud be displayed in pagination
how to use ajax pagination in cakephp .I'm also using search the database by the keywords also.. data only matches with keyword shoud be displayed in pagination
Have You tried it .. refer the book , ajax pagination example also there, and in paginator add condition option ... ie. `
$this->paginate=array((`array('condition'=>model.field )like=>%key%),limit=>10) ;

Resources