I'm trying to put a link to my web app in my blade mail template, however the url is showing like this : http://127.0.0.1:8000/.$code->discount->url. instead of a properly built, valid url.
This is how I'm doing it:
Enlace
I also tried with:
Enlace
Second way only gave me a partial url (see bellow), not the full url host and path).
$code->discount->url is /promociones/hamburguesa-de-queso
Just remove the '. .' from around the $code->discount->url:
Enlace
The url() helper is PHP function so wrapping the $code->discount->url in quotes will cause php to see it as a literal string.
Related
I need to get the name of my image and to add img folder before the name of the figure. I use url() function like below
{{ url('img', 'articles/mypic.jpg') }}
The issue is that I don't get
http://127.0.0.1:8000/img/articles/mypic.jpg
but I get %2F instead of /
http://127.0.0.1:8000/img/articles%2Fmypic.jpg
it works fine in localhost, but does not work properly on my server. I need to reconfigure apache to make it work, and I would like to avoid reconfiguring Apache. Could I avoid encoding / into %2F?
You can use urldecode, but you needn't to decode it for browser will process it well without decode.
php > echo urldecode("http://127.0.0.1:8000/img/articles%2Fmypic.jpg");
http://127.0.0.1:8000/img/articles/mypic.jpg
http://192.168.1.7/cars_store/insert_annoce.php?urlFace=firebasestorage.googleapis.com/v0/b/carsstore-1c8c5.appspot.com/o/photos%2Fimage%3A60Sat+Dec+24+10%3A39%3A10+EST+2016?alt=media&token=908e383e-1901-4c04-855d-d6c7280b40a1
$urlFace=$_GET['urlFace'];
echo $urlFace;
and this is the result of the script:
firebasestorage.googleapis.com/v0/b/carsstore-1c8c5.appspot.com/o/photos/image:60Sat Dec 24 10:39:10 EST 2016?alt=media
I always get the url missing the last part (after '&token=' ) method
Since you're passing the URL as a GET parameter within another URL, you'll have to somehow escape it so that it is distinguishable from the url that contains it.
an easy solution would be to use POST, where the data doesn't get sent as part of the URL, and therefore doesn't have this problem.
Otherwise, you'll have to encode your URI within a URI: http://php.net/rawurlencode
You can use urlencode()
This function is convenient when encoding a string to be used in a query part of a URL, as a convenient way to pass variables to the next page
Eg:
$my_url = "http://192.168.1.7/cars_store/insert_annoce.php?
urlFace=".urlencode("firebasestorage.googleapis.com/v0/b/carsstore-
1c8c5.appspot.com/o/photos%2Fimage%3A60Sat+Dec+24+10%3A39%3A10+EST+2016?
alt=media&token=908e383e-1901-4c04-855d-d6c7280b40a1");
You can use $my_url in <a> tags , form actions etc.
Then $_GET[urlFace] in annoce.php will give the full url you needed
I am new to laravel.
I want to get the last part of my url in the blade file(HTML file).
I have done this one using php functionality .
Is there any way I can get it using any laravel functionality .
Below is my code ,its working fine
<?php
$url = url()->current();
echo $end = end((explode('/', $url)));
?>
I have also used this one to get
Request::segment(2)
Here my url is http://localhost/blog/public/user/add-user.
I want to get add-user in the html file.
Thank you
Try this code for getting last value of URL
$uri_path = $_SERVER['REQUEST_URI'];
$uri_parts = explode('/', $uri_path);
$request_url = end($uri_parts);
The answer to your question is: "No there is not any Laravel functionality" or more precisely Laravel helpers for getting the last segment, but fortunately you can just use php. The end has been mentioned and end works on an array, but I don't think it is possible to use directly on Request::segments(). That means you have to put Request::segments() into a variable (like $lastSegment) first and then use end on the variable.
The best and slimmest way I could find to do this is:
{{ basename(Request::url()) }}
Use this in blade, but of course like mentioned before you can add this in the controller or a Laravel view composer.
{{last(request()->segments())}}
If you specifically want the last segment (it may be the 2nd, 3rd, 4th etc) you can use end(Request::segments()) to conistently always get the last segment.
Also, if you don't want to call functions in your templates and be a bit more 'Laravel' why not bind it to your view from the controller?
In your controller:
public function show()
{
return view('your.view')->with('lastSegment', end(Request::segments()));
}
Then in your view you can do this:
<p> The last segment is {{$lastSegment}} </p>
Also, if you want to have $lastSegment be available in all your views without having to code it in all your controllers, look into using Laravel's view composer. Very powerful for making templates.
So I'm using Postmark to send emails and the class I have requires a variable as the message body, as below:
$email->to(Input::post('email'))->subject("Verify Your Email Address")->html_message($html)->send();
This works fine if I set $html as just plain html.
What I am trying to do is send the contents of another php file from my site as this html.
I have tried:
$Vdata = file_get_contents('verification.php');
this works fine but as soon as I try and pass variables in it gives me an error:
file not found error
And sends a blank email, for example:
$Vdata = file_get_contents('verification.php?url=blah');
Essentially I just need $html to be the contents of verification.php?url=blah so that I can pass in variables to that file.
Can anyone help?
You're doing a local file inclusion, which means filenames ONLY. URLs are not permitted (query strings in particular) because you're NOT doing an HTTP request. PHP is going to look for a file whose name literally contains ?, u, r, etc... which of course doesn't exist.
If you want to use query strings, then you have to use a full-blown absolute URL, including the protocol:
include('http://....?url=...');
However, this is incredibly inefficient, and also highly dangerous. Since you're now EXECUTING the file specified in the url. you're going to get its output, not the raw PHP code in the file.
If you want to pass data to an included file, then just variables:
$foo = 'bar';
include('test.php');
and use look for/use those variables in the file.
I'm using CakePHP 2.0.4, PHP 5.3.1, Apache 2.2.14.
For example: the filename is F#7m7~1.gif. It really exists, the path and filename are correct.
Before print HTML tag, I encode it by using urlencode() and the tag goes like:
<img src="/chord/img/chords/F%2523m7~1.gif" alt="F#m7">
But the image is not loading. ('Chord' is a CakePHP Plugin)
I also tried to load it directly on the browser, http://myapp.localhost/chord/img/chords/F%2523m7~1.gif but what I get is: "Missing Controller Error: Chord.ImgController could not be found."
Everything works fine with the file as A~1.gif, but it brokes with filenames such as F#m~1.gif, B(7)~1.gif etc.
Everthing was working ok in pure PHP coded version. Now, it's not working at CakePHP.
Is there anybody have a clue?
You seem to be double-encoding it, the right urlencode for F#7m7~1.gif is F%237m7~1.gif, not F%2523m7~1.gif. Just remove one of them.
The Missing Controller error is just because there is no such file on your server, so Cake thinks you're trying to call an ImgController, within the Chord plugin. Try http://myapp.localhost/chord/img/chords/F%237m7~1.gif, it should work.
Anyway, as #GordonM pointed out, it's best to stick with normal characters for filenames.