Re: [PHP] PHP attaching css and JS files to current page

2008-11-30 Thread Eric Butera
On Sun, Nov 30, 2008 at 8:23 AM, Alain Roger <[EMAIL PROTECTED]> wrote:
> Hi,
>
> is there a way how a PHP class can attach JS (javascript) and CSS documents
> to current web page in which the class is instanced ?
> till now i used an "echo" which "write" a  code into
> current document.
> in this javascript, i used to have a createElement function to attache
> C\other CSS or JS file.
>
> it's not so clean and maybe a better possibility exists. Thanks to let me
> know.
>
> --
> Alain
> ---
> Windows XP x64 SP2
> PostgreSQL 8.3.5 / MS SQL server 2005
> Apache 2.2.10
> PHP 5.2.6
> C# 2005-2008
>

I've created a few helper classes that I use on projects for this
"problem."  What I do is have a directory that I put css and js files
into.  Then I have a main "page" class that has various sub-classes
for things like css & javascript.  Inside of a controller or view if I
have some code that needs to include a js/css file all they have to do
is something like this:

$page = page::getInstance();
$page->css->add('css.css')->add('css2.css');
$page->js->add('file.js')->add('file2.js')

By calling the add() methods page maps to that the specific js and css
directories.

Then in my main site wrapper template I call upon page again to render
out any css/js files that had been "included."  This way my design has
no idea of what js/css that needs to be included and anywhere along
the execution path of my code I can add css/js.

This also allows for some speed increases in page load since you can
get your css included in the header while delaying script includes
until way down in the body.  This prevents browsers from blocking
while compiling your scripts and the user sees something a lot faster.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] PHP attaching css and JS files to current page

2008-11-30 Thread Alex Chamberlain
Have you considered using some type of templating system, which can use
class_exists??

Alex

No virus found in this outgoing message. Scanned by AVG Free 8.0
Checked by AVG - http://www.avg.com 
Version: 8.0.176 / Virus Database: 270.9.11/1820 - Release Date: 29/11/2008
18:52


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP attaching css and JS files to current page

2008-11-30 Thread Alain Roger
you're right if you want to write them directly in the index.php.
but in my case i want the class to do it by itself.

On Sun, Nov 30, 2008 at 3:49 PM, Ashley Sheridan
<[EMAIL PROTECTED]>wrote:

> On Sun, 2008-11-30 at 15:08 +0100, Alain Roger wrote:
> > >
> > > >
> > > > Can you not just write all of the CSS/Javascript that you
> need
> > > > right
> > > > from the get-go in the same place you're writing out your
> > > > Javascript
> > > > now?
> > > >
> > > >
> > > I'm not sure I follow you then. You say you want your class to be able
> > > to include those files, then you say that you don't want to.
> > >
> > > Have you considered having PHP check for the existence of the files
> > > you're trying to include before outputting the HTML that includes them?
> > >
> > > Also, if you are outputting Javascript code that then uses a
> > > createElement to include more code, how does the Javascript know it can
> > > include the files if they don't exist for every installation?
> > >
> > >
> > so we for sure misunderstood eachother :-)
> > let's say i have an index.php page in which i create an instance of my
> class
> > CTable.
> > to do that i need to include the CTable.php file into my index.php (till
> now
> > no problem)
> > for that : include_once 'Class/CTable.php';
> >
> > in the CTable.php file i have my class definition and implementation as
> > following:
> > class CTable
> > {
> >   blah blah...
> > }
> >
> > my CTable class has a Render function which will write html code into the
> > current index.php page.
> > within this code should be written some javascript command as also some
> css
> > classnames.
> >
> > till now no problem.
> >
> > the problem is that in this code (that write my class) into index.php
> there
> > are some javascrip command and css classnames, which are linked to
> external
> > (in the Class directory) files "CTable.js" and "CTable.css".
> > those 2 files should be loaded by the class CTable itself...and this is
> what
> > i do using echo and createElement.
> > it works well but it is not clean from my point of view...that's why i
> was
> > looking for another solution...more... let say "professional".
> >
> > A.
> I still don't see the problem then with having some output that looks
> like this:
>
> print <<  href="CTable.js">
> 
> EOS;
>
> (there should be 4 lines of code there, but line-breaks crept in!)
>
>
> Ash
> www.ashleysheridan.co.uk
>
>


-- 
Alain
---
Windows XP x64 SP2
PostgreSQL 8.3.5 / MS SQL server 2005
Apache 2.2.10
PHP 5.2.6
C# 2005-2008


Re: [PHP] PHP attaching css and JS files to current page

2008-11-30 Thread Ashley Sheridan
On Sun, 2008-11-30 at 15:08 +0100, Alain Roger wrote:
> >
> > >
> > > Can you not just write all of the CSS/Javascript that you need
> > > right
> > > from the get-go in the same place you're writing out your
> > > Javascript
> > > now?
> > >
> > >
> > I'm not sure I follow you then. You say you want your class to be able
> > to include those files, then you say that you don't want to.
> >
> > Have you considered having PHP check for the existence of the files
> > you're trying to include before outputting the HTML that includes them?
> >
> > Also, if you are outputting Javascript code that then uses a
> > createElement to include more code, how does the Javascript know it can
> > include the files if they don't exist for every installation?
> >
> >
> so we for sure misunderstood eachother :-)
> let's say i have an index.php page in which i create an instance of my class
> CTable.
> to do that i need to include the CTable.php file into my index.php (till now
> no problem)
> for that : include_once 'Class/CTable.php';
> 
> in the CTable.php file i have my class definition and implementation as
> following:
> class CTable
> {
>   blah blah...
> }
> 
> my CTable class has a Render function which will write html code into the
> current index.php page.
> within this code should be written some javascript command as also some css
> classnames.
> 
> till now no problem.
> 
> the problem is that in this code (that write my class) into index.php there
> are some javascrip command and css classnames, which are linked to external
> (in the Class directory) files "CTable.js" and "CTable.css".
> those 2 files should be loaded by the class CTable itself...and this is what
> i do using echo and createElement.
> it works well but it is not clean from my point of view...that's why i was
> looking for another solution...more... let say "professional".
> 
> A.
I still don't see the problem then with having some output that looks
like this:

print <<

EOS;

(there should be 4 lines of code there, but line-breaks crept in!)


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP attaching css and JS files to current page

2008-11-30 Thread Alain Roger
>
> >
> > Can you not just write all of the CSS/Javascript that you need
> > right
> > from the get-go in the same place you're writing out your
> > Javascript
> > now?
> >
> >
> I'm not sure I follow you then. You say you want your class to be able
> to include those files, then you say that you don't want to.
>
> Have you considered having PHP check for the existence of the files
> you're trying to include before outputting the HTML that includes them?
>
> Also, if you are outputting Javascript code that then uses a
> createElement to include more code, how does the Javascript know it can
> include the files if they don't exist for every installation?
>
>
so we for sure misunderstood eachother :-)
let's say i have an index.php page in which i create an instance of my class
CTable.
to do that i need to include the CTable.php file into my index.php (till now
no problem)
for that : include_once 'Class/CTable.php';

in the CTable.php file i have my class definition and implementation as
following:
class CTable
{
  blah blah...
}

my CTable class has a Render function which will write html code into the
current index.php page.
within this code should be written some javascript command as also some css
classnames.

till now no problem.

the problem is that in this code (that write my class) into index.php there
are some javascrip command and css classnames, which are linked to external
(in the Class directory) files "CTable.js" and "CTable.css".
those 2 files should be loaded by the class CTable itself...and this is what
i do using echo and createElement.
it works well but it is not clean from my point of view...that's why i was
looking for another solution...more... let say "professional".

A.


Re: [PHP] PHP attaching css and JS files to current page

2008-11-30 Thread Ashley Sheridan
On Sun, 2008-11-30 at 14:55 +0100, Alain Roger wrote:
> In fact my class has for purpose to be used in several projects and
> therefore, to write the css/js files from the web page using the class
> would be a mistake in the way that could not be redistributed without
> missing those files.
> 
> On Sun, Nov 30, 2008 at 2:55 PM, Ashley Sheridan
> <[EMAIL PROTECTED]> wrote:
> On Sun, 2008-11-30 at 14:23 +0100, Alain Roger wrote:
> > Hi,
> >
> > is there a way how a PHP class can attach JS (javascript)
> and CSS documents
> > to current web page in which the class is instanced ?
> > till now i used an "echo" which "write" a 
> code into
> > current document.
> > in this javascript, i used to have a createElement function
> to attache
> > C\other CSS or JS file.
> >
> > it's not so clean and maybe a better possibility exists.
> Thanks to let me
> > know.
> >
> 
> Can you not just write all of the CSS/Javascript that you need
> right
> from the get-go in the same place you're writing out your
> Javascript
> now?
> 
> 
> Ash
> www.ashleysheridan.co.uk
> 
> 
> 
> 
> -- 
> Alain
> ---
> Windows XP x64 SP2
> PostgreSQL 8.3.5 / MS SQL server 2005
> Apache 2.2.10
> PHP 5.2.6
> C# 2005-2008
I'm not sure I follow you then. You say you want your class to be able
to include those files, then you say that you don't want to.

Have you considered having PHP check for the existence of the files
you're trying to include before outputting the HTML that includes them?

Also, if you are outputting Javascript code that then uses a
createElement to include more code, how does the Javascript know it can
include the files if they don't exist for every installation?


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP attaching css and JS files to current page

2008-11-30 Thread Alain Roger
In fact my class has for purpose to be used in several projects and
therefore, to write the css/js files from the web page using the class would
be a mistake in the way that could not be redistributed without missing
those files.

On Sun, Nov 30, 2008 at 2:55 PM, Ashley Sheridan
<[EMAIL PROTECTED]>wrote:

> On Sun, 2008-11-30 at 14:23 +0100, Alain Roger wrote:
> > Hi,
> >
> > is there a way how a PHP class can attach JS (javascript) and CSS
> documents
> > to current web page in which the class is instanced ?
> > till now i used an "echo" which "write" a  code into
> > current document.
> > in this javascript, i used to have a createElement function to attache
> > C\other CSS or JS file.
> >
> > it's not so clean and maybe a better possibility exists. Thanks to let me
> > know.
> >
> Can you not just write all of the CSS/Javascript that you need right
> from the get-go in the same place you're writing out your Javascript
> now?
>
>
> Ash
> www.ashleysheridan.co.uk
>
>


-- 
Alain
---
Windows XP x64 SP2
PostgreSQL 8.3.5 / MS SQL server 2005
Apache 2.2.10
PHP 5.2.6
C# 2005-2008


Re: [PHP] PHP attaching css and JS files to current page

2008-11-30 Thread Ashley Sheridan
On Sun, 2008-11-30 at 14:23 +0100, Alain Roger wrote:
> Hi,
> 
> is there a way how a PHP class can attach JS (javascript) and CSS documents
> to current web page in which the class is instanced ?
> till now i used an "echo" which "write" a  code into
> current document.
> in this javascript, i used to have a createElement function to attache
> C\other CSS or JS file.
> 
> it's not so clean and maybe a better possibility exists. Thanks to let me
> know.
> 
Can you not just write all of the CSS/Javascript that you need right
from the get-go in the same place you're writing out your Javascript
now?


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP attaching css and JS files to current page

2008-11-30 Thread Alain Roger
Hi,

is there a way how a PHP class can attach JS (javascript) and CSS documents
to current web page in which the class is instanced ?
till now i used an "echo" which "write" a  code into
current document.
in this javascript, i used to have a createElement function to attache
C\other CSS or JS file.

it's not so clean and maybe a better possibility exists. Thanks to let me
know.

-- 
Alain
---
Windows XP x64 SP2
PostgreSQL 8.3.5 / MS SQL server 2005
Apache 2.2.10
PHP 5.2.6
C# 2005-2008