laravel 8 pagination using this style for links
www.website.com/huawei?page=3
how i can make it like this?
www.website.com/huawei/3
There is not specific way. so we need to play around the existing things.
But I had made it one of my application a long time before not tested much.
may be there is much better way also to achieve it.
so may it will work same for you. Please check below way to do it as pretty url.
Route :
Route::get('/articles/page/{page_number?}', function($page_number=1){
$per_page = 1;
Articles::resolveConnection()->getPaginator()->setCurrentPage($page_number);
$articles = Articles::orderBy('created_at', 'desc')->paginate($per_page);
return View::make('pages/articles')->with('articles', $articles);
});
View :
$links = $articles->links();
$patterns = array();
$patterns[] = '/'.$articles->getCurrentPage().'\?page=/';
$replacements = array();
$replacements[] = '';
echo preg_replace($patterns, $replacements, $links);
Best Solution I had found : Please use below package for laravel which help you.
https://packagist.org/packages/spatie/laravel-paginateroute
Related
i have a database with data and i want to skip/offset the first 3 row.
$data = Data::orderBy('created_at','desc')->skip(3)->paginate(1);
$data = Data::orderBy('created_at','desc')->offset(3)->paginate(1);
both query is returning all result from the start. can anyone help me with this?
Thanks.
skip doesn't seem to work with paginate. What you can do is exclude the row by using whereNotIn.
$data = Data::orderBy('created_at','desc')->whereNotIn('id', [1,2,3])->paginate(1);
If you don't know the id you can query and use the result.
$id = Data::orderBy('created_at','desc')->take(3)->pluck('id');
$data = Data::orderBy('created_at','desc')->whereNotIn('id', $id)->paginate(1);
You can not use paginate() and skip() together. You can do is :
$data = Data::orderBy('created_at','desc')->skip(3)->take(10)->get(); and update these values skip and take values as per your custom implementation.
If you literally want to skip first 3 rows and never ever use them in pagination, you can do :
$dataToEliminate = Data::orderBy('created_at','desc')->take(3)->select('id')->pluck('id');
$data = Data::whereNotIn('id', $dataToEliminate)->orderBy('created_at','desc')->skip(3)->paginate(1);
See documentation for reference.
I have explored the paginate method from the code and came to know
$data = Data::orderBy('created_at','desc')->paginate(1, '*', null, 2);
The 4th parameter, you need to provide the page number (not the offset).
I've installed Carrot2 on a web application (PHP language). Everything works perfectly. Now i want to change the language of my results. I want to change english for french. I search on carrot2 documentation, on the web but i didn't find what i want (this link was usefull but it seems like the dcs folder had change since this post http://carrot2-users-and-developers-forum.607571.n2.nabble.com/Change-Language-in-DCS-REST-PHP-td639270.html). Anyway, i pass my paramaters (algo, query, source, etc.) with a simple form (and differents variables) and send them (PHP) to carrot2's method with curl. I tried different (strange or barbaric) ways to send french language :
$language = 'lang_fr'; // or $language = 'FRENCH'
$num = (isset($_GET["maxResult"])) ? $_GET["maxResult"] : "10";
$query = urlencode($_GET["query"]);
$source = "web";
$algorithm = "lingo";
$hierarchy = "max-hierarchy-depth";
$level_hierarchie= $_GET["deep"] ? $_GET["deep"] : "1";
$processor = new Carrot2Processor();
$job = new Carrot2Job();
$job->setSource($source);
$job->setQuery($query);
$job->setAlgorithm($algorithm);
$job->setAttribute("results", $num);
$job->setAttribute($hierarchy, $level_hierarchie);
i tried to set language like this in the setAttribute() funtion and of course it doesn't work.
$job->setAttribute("language", $language);
try {
$result = $processor->cluster($job);
} catch (Carrot2Exception $e) {
echo 'An error occurred during processing: ' . $e->getMessage();
exit(10);
}
I Also tried to change the CURLOPT_HTTPHEADER(add 'Accept-langugage: fr').
I see different responses but only for developpers using java and im using php. Is it possible to pass language choice with the setAttribute() method on PHP? Someone knows a way to do that?
Thank you in advance (i use carrot2-dcs-3.16)
For the eTools meta search engine, you can set the EToolsDocumentSource.language attribute directly in your calling code:
$job->setAttribute("EToolsDocumentSource.language", "FRENCH");
See the attribute documentation linked above for the list of supported languages.
So I'm just trying to use xeditable (http://vitalets.github.io/x-editable/docs.html#gettingstarted) to make changes to my database via AJAX.
Since I'm new to this concept and I'm (forcefully) working with PHP for the first time, I need some help.
I setup the frontend part, and a script called (say) script.php is handling the data for me (I need to write the new value in my database).
I can't really understand what to do in the script. Can someone guide me towards it? The docs above don't really do it for me.
Looking in a project I worked on a few months back (sorry about the mysql_ stuff – not my choice!)
Something like:
<?
include your/database/connection_stuff.php;
// Can't remember if x-editable passes the table in as well or not
$table = mysql_real_escape_string($_GET['table']);
// If not,
$table = 'name_of_table';
$value = mysql_real_escape_string($_POST['value']);
$name = mysql_real_escape_string($_POST['name']);
$pk = mysql_real_escape_string($_POST['pk']);
$result = mysql_query("UPDATE `$table` SET `$name` = '$value' WHERE id = '$pk'");
?>
Will do the trick.
Say my page is on:
http://localhost/app1/profile/index/123/
The result of current_url() is this:
http://localhost/app1/?profile/index/123
There is a ? that shouldn't be there. The question mark seems to be caused by the following config setting:
$config['enable_query_strings'] = TRUE;
I need query strings enabled in my application. Any ideas what I need to do?
EDIT 1:
Also, in the case when the URL does have a query string, I need current_url to also return that. I'm hoping Phil Sturgeon's solution here CodeIgniter current_url doesn't show query strings will help me.
I'm using CI 2.1.0.
As mentioned, $config['enable_query_strings'] is sort of a "legacy" setting in Codeigniter from back when there was no support $_GET (really, none).
http://codeigniter.com/user_guide/general/urls.html
Enabling Query Strings
In some cases you might prefer to use query strings URLs:
index.php?c=products&m=view&id=345
c === Your controller name
m === Your method name
The rest is the method arguments. It's a very misleading description, and there's no mention of the other setting or query strings at all in the rest of the URL docs. I've never heard of anyone actually using this. CI comes with $config['allow_get_array']= TRUE; by default, which is what you want.
You can modify the current_url() function for query string support, just create application/helpers/MY_url_helper.php and use this:
function current_url($query_string = FALSE)
{
$CI =& get_instance();
$current_url = $CI->config->site_url($CI->uri->uri_string());
// BEGIN MODIFICATION
if ($query_string === TRUE)
{
// Use your preferred method of fetching the query string
$current_url .= '?'.http_build_query($_GET);
}
// END MODIFICATION
return $current_url;
}
Then call it like current_url(TRUE) to include the query string.
Don't use: $config['enable_query_strings'] = TRUE;
Use this instead: $config['allow_get_array']= TRUE;
enable_query_strings is not what you think and is not used much.
To build your own query strings, use one of these two:
$query_string = http_build_query($this->input->get());
$query_string = $this->input->server('QUERY_STRING');
along with this:
$lastseg_with_query = $lastseg.'?'.$query_string;
Please consult this SO Q&A for more information: URI Segment with Question Mark
I need to add a custom option to all products as they get saved. For that I need to find the function that inserts the products into the database, which I'm not able to find.
Please, any help would be appreciated.
thanx
$client = new SoapClient('http://www.magentolocal.it/api/?wsdl');
$session = $client->login('productloader', '1234567890');
$sku = "123456";
$attrs['name'] = "Template #1";
$attrs['description'] = "This is the first template.";
$attrs['short_description'] = "This is the short description of the template";
$attrs['websites'] = array('1');
$attrs['price'] = "11.53";
$attrs['categories'] = array('35');
$attrs['images'] = array()
$result = $client->call($session, 'catalog_product.create', array('simple', '63', $sku, $attrs));
echo $result;
$client->endSession($session);
Magento's EAV system is pretty strung out among several files, so you won't find a single function that accomplishes what you want. If you did go looking for it, and changed it, you would also be changing the same save method that mostly every other object in Magento uses, which is probably not what you want.
To do what you want, try setting up an observer/listener on the events that catalog products use when saving, namely catalog_product_save_before or catalog_product_save_after. That way, you don't have to hack the framework.
Hope that helps!
Thanks,
Joe
How about http://www.magentocommerce.com/wiki/doc/webservices-api/api/catalog_product#catalog_product.create?