/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// sample code for thread http://expressionengine.com/forums/viewthread/174318/ class Accessory_test_acc { public $name = 'Test Accessory'; public $id = 'accessory_test_acc'; public $version = '1.0.0'; public $description = 'Test bed for accessories'; function Accessory_test_acc() { $this->EE =& get_instance(); } public function set_sections() { // Add some stuff to the head (you could alternatively load a js file from your add-on package) // @see http://expressionengine.com/user_guide/development/usage/cp.html#add_to_head // @see http://expressionengine.com/user_guide/development/usage/cp.html#load_package_js $this->EE->cp->add_to_head(" <script type='text/javascript'> $(function() { // .bind() documentation: http://api.jquery.com/bind/ $('#my_ajax_link').bind('click',function(e){ e.preventDefault(); // $.load() documentation: http://api.jquery.com/load/ $('#my_ajax_box').load($(this).attr('href'),function(){ // $.dialog() documentation: http://jqueryui.com/demos/dialog/ $('#my_ajax_box').dialog({ modal: true, title: 'Howdy', buttons: { Ok: function() { $(this).dialog('close'); } } }); }); }); }); </script> "); $this->sections['Test One'] = "<p><a id='my_ajax_link' href='".BASE.AMP."C=addons_accessories&M=process_request&accessory=accessory_test&method=process_ajax&id=232'>Click this to test the ajax return</a></p><div id='my_ajax_box'></div>"; } public function process_ajax() { // Check to make sure it's an ajax request - if not we return a user error for this example { // normall I'd build this in a view file using $this->EE->load->view('file',$data,TRUE) // but I can't seem to load a view inside these accessory methods. See this for details: // http://expressionengine.com/forums/viewthread/175547/ // http://expressionengine.com/bug_tracker/bug/14741/ $out = "<div style='margin-top:10px'>"; $out .= "<p>This content is coming from within my <pre>process_ajax()</pre> method of the accessory.</p><br/>"; $out .= "<ul>"; // Simulate some data coming from the database or something - we'll just use a basic array foreach ($array as $result) { $out .= "<li>{$result}</li>"; } $out .= "</ul>"; $out .= "</div>"; // exit(file_get_contents(dirname(__file__).'/views/entry_info.php')); } else { return $this->EE->output->show_user_error('general','Javascript is not enabled (apparently)'); } } }
URL: https://gist.github.com/736150