yii2: how to creating a back link button - button

I'm new in Yii2 and I'm not able to find something to do a back button in Yii2,
I found the solution in Yii1 is:
echo CHtml::link('Back',Yii::app()->request->urlReferrer);
but I'm not able to find a solution in Yii2,
can you help me?

Try:
echo \yii\helpers\Html::a( 'Back', Yii::$app->request->referrer);

Yii2 provides remember URLs functionality:
// Remember current URL
Url::remember();
// Remember URL specified. See Url::to() for argument format.
Url::remember(['product/view', 'id' => 42]);
// Remember URL specified with a name given
Url::remember(['product/view', 'id' => 42], 'product');
In the next request we can get URL remembered in the following way:
$url = Url::previous();
$productUrl = Url::previous('product');

Related

Dompdf stream just downloads without dialog prompt

I am using Dompdf in my Symfony 3 project and it's all working fine up until the point where I'm trying to get it to download. At the moment, it just downloads without a dialog prompt which is what I want, and according to the documentation, passing a value of 1 to the Attachment option should do this.
Here is my code:
$html = $this->renderView('pages/invoice_print.html.twig', array(
'invoice' => $invoice_array
));
$dompdf = new Dompdf();
$dompdf->set_option('isHtml5ParserEnabled', true);
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$output = $dompdf->output();
$dompdf->stream("invoice_" . $invoice->getId(), array('Attachment' => 1));
To be honest, I was under the impression that Attachment was set to 1 by default - so I'm not sure what's going on. I'm using Firefox Quantum.
EDIT:
A screenshot of how the PDF will render in the browser is now attached:
I haven't worked with dompdf in the past, but, just by glancing the code on Github, I believe I see what you need.
When you invoke stream(), you have:
if (!isset($options["compress"])) $options["compress"] = true;
if (!isset($options["Attachment"])) $options["Attachment"] = true;
So, if no Attachment option is present, the option will be set to true
Next, on line 1311, you have:
$attachment = $options["Attachment"] ? "attachment" : "inline";
header(Helpers::buildContentDispositionHeader($attachment, $filename));
which basically boils down to a Content-Disposition header:
$contentDisposition = "Content-Disposition: $dispositionType; filename=\"$fallbackfilename\"";
Finally, according to the standard, if you want to serve a file inside webpage (e.g. no prompt dialog), you need to set disposition to inline
All being said, have you tried setting Attachment to false?
$dompdf->stream("invoice_" . $invoice->getId(), array('Attachment' => false));
Hope this helps...

wordpress Front End PM

i use the plugin Front End PM
https://he.wordpress.org/plugins/front-end-pm/
And i wonder how can i make an private message throw the PHP code and not as a frontend user , i search all over here and the docs of the plugin and i found out that there is a function call 'fep_save_message' , but with no success on it...
can someone help ? , if you know other plugin that can help me throw code send a private message i want to know .
Thanks :) !
In last project we use BuddyPress and BuddyPress private message https://buddypress.org/about/private-messaging/ this work very nice.
You may try use https://wordpress.org/plugins/wp-recall/ but this is add not only PW.
You can use fep_send_message() function to send message. It supports directly post data or you can pass data as argument.
Example
$message = array(
'message_title' => 'Title of your message',
'message_content' => 'Content of your message',
'message_to_id' => 123, //Receiver id
);
$message_id = fep_send_message( $message );

Display wp author meta url without 'http'

I'm using the WP function: get_the_author_meta('user_url');
When I echo that to the browser it automatically prepends 'http://' to the URL. How can I avoid this, so that my URLs show exactly as they are entered on the user settings page.
Thanks is advance.
$author_url = get_the_author_meta('user_url'); // e.g. http://www.example.com
$to_remove = array( 'http://', 'https://' );
foreach ( $to_remove as $item ) {
$author_url = str_replace($item, '', $author_url); // to: www.example.com
}
echo $author_url; // now it will not have the http:// part you wish to avoid.
str_replace is probably the most efficient way of doing this.
$author_url = str_replace(array( 'http://', 'https://' ), '', get_the_author_meta('user_url'));
Other URL modification techniques.
For more complicated string replacements which match you could look at using preg_replace .
There is a function called http-build-url() which is included in the php_http.dll extension which might be more suitable for some use cases.

Module field with feeds, module generating data

I have an issue with triming a field before it is saved. I wanted to use substr(), or regex() with preg_match(). I have built a Drupal 7 module, but it can't work at all. I have tried using the trim plugin in feeds tamper module, but it doesn't seem to work. The data I am using is from a feed from Google Alerts. I have posted this issue here.
This is what I have done so far, and I know my regular expression is wrong; I was trying to get it do anything, just to see if I could get it to work, but I am pretty lost on how to add this type of function to a Drupal module.
function sub_node_save() {
$url = $node->field_web_screenhot['und'][0]['url'];
$url = preg_match('~^(http|ftp)(s)?\:\/\/((([a-z0-9\-]*)(\.))+[a-z0-9]*)($|/.*$)~i',$url );
$node->field_web_screenhot['und'][0]['url'] =$url;
return ;
}
I used the Devel module to get the field.
If there's an easy way to use substr(), I would consider that or something else.
Basically, I just want to take the Google redirect off the URL, so it is just the basic URL to the web site.
Depending on your question and later comments, I'd suggesting using node_presave hook (http://api.drupal.org/api/drupal/modules!node!node.api.php/function/hook_node_presave/7) for this.
It's called before both insert (new) and update ops so you will need extra validations to prevent it from executing on node updates if you want.
<?php
function MYMODULE_node_presave($node) {
// check if nodetype is "mytype"
if ($node->type == 'mytype'){
// PHP's parse_url to get params set to an array.
$parts = parse_url($node->field_web_screenhot['und'][0]['url']);
// Now we explode the params by "&" to get the URL.
$queryParts = explode('&', $parts['query']);
$params = array();
foreach ($queryParts as $param) {
$item = explode('=', $param);
$params[$item[0]] = $item[1];
}
//valid_url validates the URL (duh!), urldecode() makes the URL an actual one with fixing "//" in http, q is from the URL you provided.
if (valid_url(urldecode($parms['q']))){
$node->field_web_screenhot['und'][0]['url'] = urldecode($parms['q']);
}
}
}

Passing URIs as URL arguments in Drupal 6

I'm running into problems trying to pass absolute URIs as parameters with clean URLs enabled.
I've got hook_menu() set up like this:
function mymodule_menu() {
return array(
'page/%' => array(
'title' => 'DBpedia Display Test',
'page callback' => 'mymodule_dbpedia_display',
'page arguments' => array(1),
),
);
}
and in the page callback:
function mymodule_dbpedia_display($uri) {
// Make an HTTP request for this URI
// and then render some things
return $output;
}
What I'm hoping to do is somehow pass full URIs (e.g. "http://dbpedia.org/resource/Coffee") to my page callback. I've tried a few things and nothing's worked so far...
http://mysite.com/page/http%3A%2F%2Fdbpedia.org%2Fresource%2FCoffee Completely breaks Drupal's rewriting
http://mysite.com/page/?uri=http%3A%2F%2Fdbpedia.org%2Fresource%2FCoffee Gives a 404
http://mysite.com/page/http://dbpedia.org/resource/Coffee Returns just "http:", which makes sense
I could probably use $_GET to pull out the whole query string, but I guess I'm hoping for a more 'Drupal' solution. Any suggestions?
I have had this problem before, trying to do the same thing (RDF browsing). I got round it by using rawurlencode and rawurldecode on the URI.
So when creating link do
l('Click Here', 'page/' . rawurlencode($uri));
and when using your $uri variable do a rawurldecode();
$uri = rawurldecode($uri);
It will give you a URI something like
http://mysite.com/page/http%253A%252F%252Fdbpedia.org%252Fresource%252FCoffee
Instead of using page/%, use page/%menu_trail. %menu_trail will pass the rest of the URL as a single string that in your example will be passed to the menu callback as $uri.
If the source of the urls is something you control, why don't you use a reversible encoding, like base64, to encode the string and therefore remove any tricky characters, then decode when you execute your menu callback. Eg:
$link = 'http://www.example.com?uri='. base64_encode($uri);
...
function mymodule_dbpedia_display($uri) {
$uri = base64_decode($uri);
// Make an HTTP request for this URI
// and then render some things
return $output;
}
This should just work; it's a known bug in Drupal. You could try the patches in that thread, but your best bet may be to just do a different encoding on top of URL encoding, as others have suggested.
It's much easier than all this so long as you get to encode your own URIs - read these docs, all secrets shall be revealed: drupal_urlencode()
Cheers

Resources