lehtu Posted February 4, 2015 Share Posted February 4, 2015 Hi, I have this situation I'm working on my template file and $page is what I want.. But I just want to add one field to it. And there is more.. I don't want to save it. So I just want to add new $field to my $page object virtually. After this I'm going to change it to JSON and print it out. Is this possible? If yes, please share the answer Thanks! Link to comment Share on other sites More sharing options...
LostKobrakai Posted February 4, 2015 Share Posted February 4, 2015 If the field your settings a value for is not reserved or found in the templates fields it's just added to the object as runtime property. $page->notAAssingedField = "Hello"; echo $page->notAAssingedField; // outputs: Hello If you'd need more specific additions you could also use hooks to extend the page object or even make a own object, extending the existing page object. This new object can then be assinged to specific templates in the backend. Edit: As you've said you'll export it to JSON: A page object has lots of properties, which I don't know if you need all of them. So I would suggest taking a look at the json so it's not bloated with stuff you're not using, especially if it's for something like ajax. 2 Link to comment Share on other sites More sharing options...
renobird Posted February 4, 2015 Share Posted February 4, 2015 Do you need this field to be shown in the admin or frontend? Are you just setting a value programatically, or does it require user input? I see now "in template". Link to comment Share on other sites More sharing options...
kongondo Posted February 4, 2015 Share Posted February 4, 2015 Unless am mistaken, this is called overloading. In PHP, you can overload both properties and methods. Overloading in PHP provides means to dynamically "create" properties and methods. These dynamic entities are processed via magic methods one can establish in a class for various action types. http://php.net/manual/en/language.oop5.overloading.php http://phppot.com/php/overloading-in-php/ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now