magento2 product collection keeps on loading - magento2

i was tring to get product collection to show in slider in magento2. i tried
http://blog.chapagain.com.np/magento-2-get-product-collection/
to get product collections. but my page keeps on loading. so i commented out everything in the function
public function getProductCollection()
{
$collection = $this->_productCollectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->setPageSize(3); // fetching only 3 products
return $collection;
}
page loaded successfully. So please suggest how i can get product list with images.

The issue is fixed just by empty the folder var/generation and refreshing the page.

Related

Backpack for laravel - inline-create many-to-many relation

I am using Laravel BackPack Pro and I can't get full modal form for inline-create relation... It was working early, but after some coding and updates I found that this feature dosen't work any more with no any errors =\
My main model is Image, which has Tags (many-to-many) and Category (belongs-to) related models
Category inline-create still working! But tags - not.
I have no any errors, but the response of modal request - returns with only initial form, buttons and with NO any fields:
Common tag create action is Ok, and I did't rewrite any modal views.
Can someone explain what can be wrong?
Ok, I got it!
My setup tag crud controller was
public function setup() {
...
$this->crud->operation(['create', 'update'], function () {
...
}
}
But when I exclude create operation to separate method
protected function setupCreateOperation() {
...
}
all started working as expected!

Laravel Query builder returning multiple values

Code on page one view:
#foreach($customers as $customer)
edit
#endforeach
On page one controller
function edit($id){
$customer1 = Customer::find($id)->get();
return view('page2', compact('customer1'));
}
My route on web.php
Route::get('page2\{id}', page1controller#edit);
Now the thing is id is a primary key so there's no cases of redundancy. However I am getting all the multiple records(all records) on the next page.
On page2 I need to display value related to the customer clicked on the first page although its showing me all the records
I checked my db there is no redundant ids.
On the find() function don't put the ->get(), that's why it returns all values of the Customer model.
Check docs here about that function.
I think you need to remove ->get() entirely.
Instead of using find($id)->get();, use find($id);
it should look like below.
function edit($id){
$customer1 = Customer::find($id);
return view('page2', compact('customer1'));
}
This should return the customer whose id is passed as the parameter

Ionic 3 NavParams Pushing Data from Page 1 to Page 3

I’m working on an application with multiple different pages and I need some help.
My application retrieves data from a database in Parse, and I am using providers in order to share this data to my other pages.
My main page (Page 1) asks the user to select a city. Based on the user’s selection, the next page (Page 2) will display data specific to that city, and also has links to resources that will lead to Page 3.
My issue is that Page 3 lists data for all the cities, instead of the city that was selected in Page 1.
Is it possible to pass the data from page 1, to page 2, and page 3?
So far, I have tried this:
Page 1:
selectCity(item) {
this.navCtrl.push( {item : item} };
}
Page 2:
city: any;
this.city = this.navParams.get(‘item’);
// there is an array ‘resource’ which contains names of different pages. this method pushes the selected page.
selectResource() {
this.navCtrl.push(resource.page)
}
Page 3:
city: any;
this.city = this.navParams.get(‘item’);
When I try to display the value of this.city in the console log, it says undefined.
Pushing a page and adding parameter like so:
this.navCtrl.push(resource.page, {item: item});
Please note that you are missing the second parameter item on page 2 on selectResource()
Retrieve the data on page 3 (in the constructor for instance) like so
this.city = this.navParams.get('item');
Please also note, that you may want to use an provider. This allows you to share data throughout the application.
Here you will find more info on that:
https://www.gajotres.net/ionic-2-sharing-data-between-pagescomponents/2/

Refreshing dynamic form fields after data has changed

I have a ColdFusion page that has, among other things, forms that are built using DataTables.
This page manages a handful of things (documents, categories, doctypes, etc) and each tab has CRUD functionality going on.
Initially, on each tab, it simply displays the current set of (fill in the blank) but if you click the create/update links/icons, the form to do so pops up. Some of the form fields are actually lists of the others. For example, if I want to upload a new document, one of the form fields is the category for that document.
I get the information for that form field by using cfinvoke to a get function in a cfc, which returns as a query and I loop through, populating the dropdown.
My problem is this: If I go and create a new category on the category tab I need the dropdown of category choices to update over on the new document form. However, it's already been populated and won't recheck that info until I refresh the page and thus won't show my new category in the dropdown.
The way I see it, I need to reinvoke the CFC method, repopulating the query variable and then refresh the form to make it loop through the new data and fully populate the dropdown.
I've tried to call the cfinvoke and reset the form from within the callbacks section of the DTHelper() but that (kind of as expected) didn't work.
How would I force the refreshing of the data, and subsequently, the form when this all takes place using AJAX and the actual page never reloads? Or should I just be forcing a page reload in this situation? (which works, I tried that, but it's a page refresh)
So, my boss figured it out. You have to use drawCallback().
In my example it worked like so. First, give all your major category select boxes a class:
<select name="majorCategoryID" class="major-category-select">
...
</select>
Then modify the DataTable options for major category:
majorcat_dt = $("#majorcat-dt").DataTable({
ajax: "blah"
columns: [{ blah }],
drawCallback: function() {
/* remove all options from select boxes */
$(".major-category-select option").remove();
/* this is the crazy DataTables api call to get rows */
this.api().rows().data().each(function(row) {
$(".major-category-select").append("<option value='"+row.id+"'>"+row.name+"</option>");
});
}
});
This also removed the need for the cfinvoke in the first place since this also populates the dropdowns on page load as well.
Here is how I did something like that once.
javascript:
var minutes = 10;
var refreshInterval = minutes * 60 * 1000; // to get milliseconds
jQuery.fn.populateCensusDiv = function() {
$.ajax({
type:"POST",
url:"censusData.cfc?method=getCensusData",
cache:false,
success: function(msg) {
$("#census").html(msg);
}
});
setTimeout(function() {
$("#census").populateCensusDiv();
}, refreshInterval);
return this;
ColdFusion function
<cffunction name="getCensusData" access="remote" returntype="string"
//deleted code
returnFormat = "plain">
<cfscript>
var returnString = "";
</cfscript>
more code
<cfsavecontent variable="returnString">
more code
</cfsavecontent>
<cfreturn returnString>
</cffunction>
My context was an html table that got refreshed every 10 minutes. You can adapt it for your own needs.

Zend Framework - Change order of action output

I have two actions for image albums in my controller, the first creates a form to create a new album and handles the POST and the second generates a list of the existing albums. The form posts to the first action and then puts the list action on the actionstack. This order is necessary as otherwise a newly created album wouldn't appear in the list.
So in my HTML output there is first the output of the createAction-view and then of the listAction-view. But for styling reasons I want to change the order of view output of the two actions in my HTML. Is there a way I can have the list followed by the form without changing the order in which the actions are executed?
You should try and avoid using the action stack if at all possible. You can avoid this requirement completely by simply redirecting to the list view after handling the POST data. This also prevents users accidentally submitting the same album again by refreshing the page. If you still want the form to be displayed under the list, just add the form to that action as well so you can output it in the view under your albumn list.
public function createAction()
{
$form = new Yourapp_Form_Album();
if ($this->getRequest()->isPost()) {
if ($form->isValid($this->getRequest()->getPost()) {
// save the data and redirect
}
}
$this->view->form = $form;
}
public function listAction()
{
// load albums and assign to the view
// if you want the form under the list
$this->view->form = new Yourapp_Form_Album();
}