PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » HTML_Page » Bug #814

prependBodycontent

Details

Request #814prependBodycontent
Submitted2004-02-20 18:00 UTC
Fromdostick at ctco dot lv
Assignedthesaur
StatusClosed
PackageHTML_Page
PHP Version4.3.4
OSUNIX
Roadmaps(Not assigned)

Comments

[2004-02-20 18:00 UTC] dostick at ctco dot lv

Description:
------------
Sometimes it is necessary to add content before other content( beginning of page).
This function does that:

/**
* Add body content bofore other content
*
* @param string $content
* @access public
* @return void
*/
function prependBodyContent($content)
{
array_unshift($this->_body,$content);
} // end func

[2004-02-25 13:56 UTC] thesaur at php dot net

Thanks for the feature request! I'm considering working it into the addBodyContent method. Here is a patch. Does that sound good to you? By default, it works as it always has. If you call it as

$page->addBodyContent($content,1);

it appends and

$page->addBodyContent($content,2);

replaces the whole content.

If that sounds good, I'll consider declaring the following constants:
- HTML_PAGE_BODY_APPEND
- HTML_PAGE_BODY_PREPEND
- HTML_PAGE_BODY_REPLACE

They could then be passed as the flag.

Index: Page.php
===================================================================
RCS file: /repository/pear/HTML_Page/Page.php,v
retrieving revision 1.33
diff -u -r1.33 Page.php
--- Page.php 30 Jan 2004 22:42:20 -0000 1.33
+++ Page.php 25 Feb 2004 13:57:32 -0000
@@ -700,11 +700,18 @@
* Objects must have a toString method.
*
* @param mixed $content New <body> tag content (may be passed as a reference)
+ * @param int $flag Determines whether to prepend, append or replace the content
* @access public
*/
- function addBodyContent($content)
+ function addBodyContent($content, $flag = 0)
{
- $this->_body[] =& $content;
+ if ($flag == 2) {
+ $this->setBody($content);
+ } elseif ($flag == 1) {
+ array_unshift($this->_body, $content);
+ } else {
+ $this->_body[] =& $content;
+ }
} // end addBodyContent

/**

[2004-02-25 14:12 UTC] dostick at ctco dot lv

Good idea with flags.
I think method prependBodyContent should exist too. As a wrapper calling addBodyContent($content,1)

Your patch failed on my system though.
When is the next release coming?

[2004-02-25 14:20 UTC] thesaur at php dot net

Will integrate this in the next release.

[2004-02-25 16:21 UTC] thesaur at php dot net

This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pear.php.net.

In case this was a pear.php.net website problem, the change will show
up on the website in short time.

Thank you for the report, and for helping us make PEAR better.