Anzeo Posted October 19, 2009 Share Posted October 19, 2009 Hi all, I'm currently implementing some AJAX features in my PHP-framework (which is based on TemplatePower) and I have encountered a problem: I have a block which holds a message-div. This block is called upon (with the ->newBlock() method) by my message class. This way of showing message has worked great up until now (because every time a message should been shown, the page should be reloaded anyway). But now I want to show a message when I click on a checkbox WITHOUT reloading the page. As I expected I received following error: Fatal error: Call to a member function newBlock() on a non-object in /home/www.myurl.com/message.php on line 28 And on line 28 i call $tpl->newBlock("MESSAGE"); where $tpl is an instance of TemplatePower. As I didn't find a clear tutorial/solution for this via Google I'm presenting this problem to you guys: Is there an easy way to keep my current structure (with the template blocks) and let AJAX make use of this? Or should I rethink the structure? TIA, Anzeo Link to comment https://forums.phpfreaks.com/topic/178195-templatepower-ajax/ Share on other sites More sharing options...
Gayner Posted October 19, 2009 Share Posted October 19, 2009 Give us the code all of it, were that object get's called. Link to comment https://forums.phpfreaks.com/topic/178195-templatepower-ajax/#findComment-939516 Share on other sites More sharing options...
Anzeo Posted October 19, 2009 Author Share Posted October 19, 2009 I know what causes the error, I want to know if there are people who're using TemplatePower in combination with AJAX; The problem is once my php page is parsed (via the TemplatePower object), I cannot add new block or assign variables without having to reload the whole page (because the $tpl object isn't there anymore). I know this sounds vage, but actually I'm not asking for code, just if someone knows a method to make this work. Thanks for your response! Anzeo Link to comment https://forums.phpfreaks.com/topic/178195-templatepower-ajax/#findComment-939612 Share on other sites More sharing options...
PFMaBiSmAd Posted October 19, 2009 Share Posted October 19, 2009 Every http request is separate from every other http request. Web servers are stateless. They don't know or care what pages have been requested before or after any particular page and when they finish 'serving' any particular page all the resources used on that page are destroyed/freed up. The page you request through an AJAX http request must be a complete page that contains an instance of your $tpl object. If you expect the AJAX http request to be able to access a $tpl object that was created when the main page was first requested, you would need to use a session to hold the instance of that object, because that object that was created when the main page was requested was also destroyed when the web server was finished outputting the main page to the browser. Link to comment https://forums.phpfreaks.com/topic/178195-templatepower-ajax/#findComment-939617 Share on other sites More sharing options...
Anzeo Posted October 19, 2009 Author Share Posted October 19, 2009 Err.. PFMaBiSmAd, may I suggest that you're AWESOME? I think I now know how to make this work. I'll just split my page up into two seprate templates: one for the general part (HTML-headers etc.) and one for the dynamic content (which then can be loaded by AJAX). Thanks! I'll let you guys know if it works out like this. Link to comment https://forums.phpfreaks.com/topic/178195-templatepower-ajax/#findComment-940076 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.