jimbo_3000 Posted February 1, 2009 Share Posted February 1, 2009 i am working with this code and i am trying to separate one section so i can just call it over and over but it is not working. I tried putting the page by itself but it won't work when i call it. What is the proper way of calling this function? <?php require_once('requires.php'); require_once('PhotoShareBase.php'); class CreateAccountPage extends PhotoShareBase { public function __construct() { parent::__construct(); } public function title() { return 'Create Account'; } public function inlineStyle() { $style = <<<EOSTYLE label { margin-top: 0.5em; display: block; font-family: Arial, Helvetica; font-size: 10pt; color: #444; } EOSTYLE; return parent::inlineStyle() . $style; } protected function generateBodyContents() { parent::generateBodyContents(); if (User::amILoggedIn()) { echo 'Sorry, you can\'t be logged in when viewing this page'; return; } echo <<<EOCONTENTS <h3>Create a New User Account</h3> <form method='post' action='SubmitAccountData.php' name='create_user_form'> <div> <label>User Name:</label> <input type='text' name='user_name' size='30'> </div> <div> <label>Full Name:</label> <input type='text' name='full_name' size='30'> </div> <div> <label>Password:</label> <input type='password' name='password1' size='20'> </div> <div> <label>Password (confirm):</label> <input type='password' name='password2' size='20'> </div> <div> <label>Email Address:</label> <input type='text' name='email_address' size='30'> </div> <div> <label>User Bio:</label> <textarea name='user_bio' rows='10' cols='40'></textarea> </div> <p><input type='submit' value='Create User'></p> </form> EOCONTENTS; } } $page = new CreateAccountPage(); $page->processRequest(); ?> this is the code that is repeating i want to call it separately i tried a few things and it did no work. It is mainly css but I still wanna be able to call it. public function inlineStyle() { $style = <<<EOSTYLE label { margin-top: 0.5em; display: block; font-family: Arial, Helvetica; font-size: 10pt; color: #444; } EOSTYLE; return parent::inlineStyle() . $style; } Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted February 1, 2009 Share Posted February 1, 2009 You can call methods without instantiating a class by prefixing the method with static (eg. static public function x()) and envoke the method by ClassName::methodName(). That said, you really should look into object oriented programming techniques and the paradigms associated with them as this code kind of feels like you're just programming in classes as if it was procedural programming. Quote Link to comment Share on other sites More sharing options...
jimbo_3000 Posted February 1, 2009 Author Share Posted February 1, 2009 You can call methods without instantiating a class by prefixing the method with static (eg. static public function x()) and envoke the method by ClassName::methodName(). I'm not sure what you mean by the above can direct to an example? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted February 1, 2009 Share Posted February 1, 2009 From: http://us2.php.net/language.oop5.static <?php class Foo { public static function aStaticMethod() { // ... } } Foo::aStaticMethod(); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.