-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added ability to add attributes to html() method #46
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -650,9 +650,17 @@ public function __toString() | |
/** | ||
* Returning basic html code for this image | ||
*/ | ||
public function html($title = '', $type = 'jpg', $quality = 80) | ||
{ | ||
return '<img title="' . $title . '" src="' . $this->cacheFile($type, $quality) . '" />'; | ||
public function html($title = '', $type = 'jpg', $attributes = array(), $quality = 80) | ||
{ | ||
$html = array(); | ||
if (!empty($attributes)) { | ||
foreach ((array)$attributes as $key => $value) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should typehint There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. array required, with type casting you can pass things without array too. |
||
if (is_numeric($key)) $key = $value; | ||
if (!is_null($value)) $key . '="' . $value . '"'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line doesn't do anything, because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, this line has no effect agreed. |
||
$html[] = $key . '="' . ($value) . '"'; | ||
} | ||
} | ||
return '<img title="' . $title . '" src="' . $this->cacheFile($type, $quality) . '" ' . implode(' ', $html) . '/>'; | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you do this test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't want to set any attribute, only want to change the quality of image you can pass null and empty array or no array at all. That will just change the quality of image and no attribute are added to the output.
Eg:
html('title','jpeg','',20))
orhtml('title','jpeg',NULL,20))
orhtml('title','jpeg',array(),20))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but since the
foreach
loop will not have any effect in this case the test is not usefulThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foreach
is not execute only when you pass theNULL
, if you pass an empty array or and empty string it will executed at least one time