view loop many times codeigniter 4.3.1 - codeigniter

I have one error when click on cate list, view loop many times
i am using ci4, i try dd var when click on cate which is correct, but when i return view loop many times in this function,
i dont know where is error,
here is my reposi and include database
please view and check it to me
thank
https://github.com/tranhuuphu/CI4_App
solve errors in view
here is code
route line 3
$routes->get('/', 'CanvasController::index');
$routes->get('(:any)/(:any)-(:num).html', 'CanvasController::post/$1/$2/$3');
$routes->get('(:any)', 'CanvasController::postCate/$1');
controller
public function postCate($slug5){
// dd($slug);
return view('front_end/canvas_site/post_cate');
}
you look detail in my Reposity (include database), click on category, the main layout loop many times, but when route with detail post it is ok.
thank for reading and helping

Related

Don't load table on first load Oracle ADF

Everytime my page comes up it executes the table query. I tried doing this,
https://blogs.oracle.com/shay/entry/preventing_queries_when_page_f
but it still happens. How can I fix this? I've tried setting the refresh condition to never, but then I can't get any data back. I'm using JDev 11g.
Thanks.
I can share how I did this in JDeveloper 12.1. I am not sure whether it works in 11g. Nor am I sure it's the best way to do it. But it worked for me.
The idea is to not prevent the initial query execution, but, rather, to make sure it happens quickly and returns no data. The approach is to set the initial query criteria in the View Instance of your Application Module.
This approach assumes you have at least one bind variable in your view object. If you do not, you will need to add one just for this.
Double click on the Application Module
Click on the "Overview" tab at the bottom
Click on the "Data Model" tab on the left, so that you are viewing the Data Model Components of your Application Module
In the "Data Model" tree on the right, click once on the View Object Usage ("MyObjectVO1", e.g.).
Click the "Edit..." in the upper-right corner of the Data Model tree.
Here, you can specify view criteria to be used initially for the page. So,
* Set an initial parameter that will (A) execute quickly and (B) return no data
Then, later, programatically reset the bind variables to correct values that will return data, when you are ready to let your query run.
The most simple way i know is to set up correctly "Refresh" attribute on iterator in the page definition.
To do that set refresh=ifNeeded, then set RefreshCondition with expression language, something like this: #{viewScope.yourBean.refresh}
public class YourBeanClass {
private boolean refresh = false;
public void someAction(ActionEvent actionEvent) {
//some custom logic to set refresh flag
refresh = true;
}
public boolean isRefresh() {
return refresh();
}
}
With this code you can simply manage the moment when you need to refresh your model.
While these solutions will work to prevent the query from executing, I would ask what is the use case that a user sees a table appear on a web page without doing a search first?
ADF is built to query automatically because normally a web page will have an af:query or af:quickquery component on the page to allow the user to enter a query. Once the query is executed, the results are returned and populate the table or form (depending on the page design). Including either of these search components on the page will prevent the page from executing the query until the search is executed. You can also execute a query on entry to the page using a taskflow and adding an Execute operation from the data control to the navigation into/prior to getting to the page.
Note that Shay's blog post is from 2009 and covers the use case of not using a search component and instead uses Execute with Params. Is this what you are using? Saying more about your use case would be helpful.

laravel newbie- syntax for making/setting variable in view with a function in the controller

I've started my first project in laravel (following along with the beginner laracasts series). I've successfully made a 'joggers' scope and get_joggers() function in the controller to pass that set of data to a view- great!
So now- I have a view where I pass all the people, and a partial to show different subsets of them, like so:
#include ('partials._people_list', ['person_group' => $joggers]);
My question: On a view page, what's the syntax declare/set a variable to the results of a function in the controller? I would imagine something like this, but since a view page wants HTML I'd at least have to put it in some php tags or something (though there's probably a better way):
$person_group = action('PeopleController#get_joggers');
This seems so painfully basic, but the first 27 laracasts didn't get there and I've been hunting around for while. Thanks in advance for any help!
Update! I talked to a buddy at work, and the answer was to make/set $joggers in the PeopleController, and then pass it all along like so:
public function index()
{
$people = Person::latest('created_at')
->displayable()
->orderBy('last', 'asc', 'first', 'asc')
->get();
$joggers= Person::joggers('created_at')->get();
return view('person.index', compact('people', 'joggers'));
I've returned different types of data before, and it hadn't occurred to me that I could send two different collections of people. Mystery solved :)

Laravel4 pagination is stuck

I have a quite-complex query with lots of joins and wheres via Eloquent instance which starts with
$user = new User;
$query =User::join('table','users.id','=','table.id');
After that i'm looping and adding lots of ->whereRaw() entries.
In the end of it, im running:
return $query->paginate(30);
on the view itself i'm running
{{ $records->appends($_GET)->links() }}
Everything looks OK but the thing is that after the first page (when I paginate to page #2) the paginator links are stuck on 2 and doesnt go on.
Probably a CodeIgniter thinking tried on Laravel.. ;)
You're passing the page number to appends (as you're passing the whole of $_GET) which is why it gets stuck. Either be more specific with your appends call or use Input::except('page') or similar.

Prestashop: Get id of parent category

I've faced the problem while coding my very first prestashop template. So what I want to do is to get the list of all sub categories which are under the same parent category. So running foreach loop I need to send parent category id.
In the internet there's not so much information about prestas' coding, modules or stuff, but I found two possible solutions.
One was: {$product->id_category_default} but that works only inside a product page (?) Maybe I'm wrong and it's possible to get a solution with this?
Another way sounds bit desperate: {$cookie->last_visited_category}
problem with this one, that it works only if you come from parent category directly, but fails when followed by direct link or any other way.
Also I was thinking of writing php function, which sends MySQL query and returns parent category id, but is this optimal way to do? Also I haven't tried writing my own php functions in smarty, seems it woks in some different way than just calling function.
So to conclude, do anyone knows how to get parent category id without separate php function and if it's so desperate, where and how to define your own php functions for smarty and how to call them.
I'm working with prestashop 1.4.
Thank you for your attention.
I've used this code in a module, you might need to adapt it but basically, the id of the parent category is stored in the database.
$parentCategoryList = array(2, 3, 4, 5);
if(!in_array($id_category, $parentCategoryList)){
$parentCategory = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT DISTINCT c.id_parent
FROM '._DB_PREFIX_.'category c
WHERE c.id_category = '.(int)($id_category)
);
$id_category_parent = $parentCategory[0]['id_parent'];
}
else{
$id_category_parent = $id_category;
}
In my code, the $parentCategoryList stores the id of my main categories (change it to your values). Then it checks if the category you're viewing ($id_category) is a main category. If not, it looks for the parent category in the database.
I am not really happy about the use of an array to store manually the main categories, but it works.
Hope this helps!

ReportEvent not working for posting critical category events

I need to report an event that comes under critical category.
Rest is working fine but i am having problems with using the ReportEvent for posting "critical" category event.
Code sample is something like:
const WORD LM_NT_LOG_CATEGORY_CRITICAL = 1;
WORD category;
category = LM_NT_LOG_CATEGORY_UNKNOWN;
ReportEvent(hEventSource,logLevel,category, event,NULL,2,0,
(const TCHAR**) &lpszStrings,
NULL);
In Windows Event Viewer for this particular event i see a "1" in Category column instead of "critical".
Can anyone please help me?
In order to get strings displayed in the Event Viewer you have to provide (and possibly localize) a mapping from your numeric categories. The rules are here.
Categories can be stored in a separate message file, or in a file that
contains messages of other types. If you create a single message file,
be sure that the categories are the first messages in the file.

Resources