Blesta Addons Posted July 17, 2014 Report Posted July 17, 2014 i'm writing a plugin for "my private notes"->PauloV hack . the probleme the widget is not displaying the vars as array . when i set the vars as unique value like $vars = "test" ; it show in the widget , when i set vars to array i can't dump the value $data = array( 'test' => "test", 'user_id' => $tuser_id, 'company_id' => $this->company_id, ); is there any special tips for resolving this ? Quote
Tyson Posted July 17, 2014 Report Posted July 17, 2014 i'm writing a plugin for "my private notes"->PauloV hack . the probleme the widget is not displaying the vars as array . when i set the vars as unique value like $vars = "test" ; it show in the widget , when i set vars to array i can't dump the value $data = array( 'test' => "test", 'user_id' => $tuser_id, 'company_id' => $this->company_id, ); is there any special tips for resolving this ? Not sure I fully understand the problem here, but based on your example, I don't see $vars set in $data. $vars = array('field' => "value"); $data = array( 'test' => "test", 'user_id' => $tuser_id, 'company_id' => $this->company_id, 'vars' => $vars ); Quote
Blesta Addons Posted July 17, 2014 Author Report Posted July 17, 2014 Not sure I fully understand the problem here, but based on your example, I don't see $vars set in $data. $vars = array('field' => "value"); $data = array( 'test' => "test", 'user_id' => $tuser_id, 'company_id' => $this->company_id, 'vars' => $vars ); i will prepare the code and back to you again . what does mean this error Undefined property: MyprivateNotesStaff::$Record MyprivateNotesStaff is a model class ; Quote
Blesta Addons Posted July 17, 2014 Author Report Posted July 17, 2014 CODE as normal plugin in a page work perfectly , but as a widget is not working , is not displaying anything , even if the box widget . is there any tips to enable debug in widget ? my code as following controllers/admin_main.php /** * Pre-action */ public function preAction() { parent::preAction(); $this->requireLogin(); Language::loadLang("myprivate_notes_plugin", null, PLUGINDIR . "myprivate_notes" . DS . "language" . DS); // Set the plugin ID $this->plugin_id = (isset($this->get[0]) ? $this->get[0] : null); // Set the company ID and staff ID $this->company_id = Configure::get("Blesta.company_id"); $this->staff_id = $this->Session->read("blesta_staff_id"); $this->user_id = $this->Session->read("blesta_id"); } /** * Renders the system overview widget */ public function index() { // Only available via AJAX if (!$this->isAjax()) { $this->redirect($this->base_uri); } // $data = array(); $this->uses(array("Users")); $this->uses(array("MyprivateNotes.NotesStaff")); // $this->company_id = Configure::get("Blesta.company_id"); // $this->staff_id = $this->Session->read("blesta_staff_id"); // $this->user_id = $this->Session->read("blesta_id"); // Set my info notes if (empty($data)) { $staff = $this->NotesStaff->getNotes($this->staff_id, $this->company_id); // $staff->notes = $this->Users->systemDecrypt($staff->notes); // disabled temporary $data = (object)(array)$staff; } $this->set("data", $data); return $this->renderAjaxWidgetIfAsync(false); } models/notes_staff.php class NotesStaff extends MyprivateNotesModel { /** * Initialize */ public function __construct() { parent::__construct(); } /** * Fetches a staff member notes * * @param int $staff_id The ID of the staff member * @param int $company_id The ID of the company to set staff settings for (optional, if null, no settings will be set) * @return mixed An array of objects or false if no results. * @see Staff::getByUserId() */ public function getNotes($staff_id, $company_id=null) { $fields = array("staff.id", "staff.user_id", "staff.notes"); $staff = $this->Record->select($fields)->from("staff")-> where("staff.id", "=", $staff_id)->fetch(); return $staff; } } views/admin_main.pdt <?php $this->Widget->clear(); $this->Widget->setWidgetButton("arrow"); $this->Widget->create($this->_("MyprivateNotesPlugin.notes.heading_notes", true), array('id'=>"widget_myprivate_notes_admin_main")); //$this->Widget->create(); ?> <div class="inner"> <div class="pad"> <?php $this->Html->_($data->notes); ?> </div> </div> <?php $this->Widget->end(); ?> as i mentioned before , it work perfectly as a normal plugin , when i change to the widget , nothing is displayed when i comment out the set function in controller , the box widget displayed normally . Quote
Tyson Posted July 17, 2014 Report Posted July 17, 2014 i will prepare the code and back to you again . what does mean this error Undefined property: MyprivateNotesStaff::$Record MyprivateNotesStaff is a model class ; That means that you are attempting to reference $this->Record, but that component has not been loaded. I think your widget should be created with a $render_section set for AJAX support: $this->Widget->create($this->_("MyprivateNotesPlugin.notes.heading_notes", true), array('id'=>"widget_myprivate_notes_admin_main", $this->Html->ifSet($render_section, null))); CODE as normal plugin in a page work perfectly , but as a widget is not working , is not displaying anything , even if the box widget . is there any tips to enable debug in widget ? my code as following controllers/admin_main.php /** * Pre-action */ public function preAction() { parent::preAction(); $this->requireLogin(); Language::loadLang("myprivate_notes_plugin", null, PLUGINDIR . "myprivate_notes" . DS . "language" . DS); // Set the plugin ID $this->plugin_id = (isset($this->get[0]) ? $this->get[0] : null); // Set the company ID and staff ID $this->company_id = Configure::get("Blesta.company_id"); $this->staff_id = $this->Session->read("blesta_staff_id"); $this->user_id = $this->Session->read("blesta_id"); } /** * Renders the system overview widget */ public function index() { // Only available via AJAX if (!$this->isAjax()) { $this->redirect($this->base_uri); } // $data = array(); $this->uses(array("Users")); $this->uses(array("MyprivateNotes.NotesStaff")); // $this->company_id = Configure::get("Blesta.company_id"); // $this->staff_id = $this->Session->read("blesta_staff_id"); // $this->user_id = $this->Session->read("blesta_id"); // Set my info notes if (empty($data)) { $staff = $this->NotesStaff->getNotes($this->staff_id, $this->company_id); // $staff->notes = $this->Users->systemDecrypt($staff->notes); // disabled temporary $data = (object)(array)$staff; } $this->set("data", $data); return $this->renderAjaxWidgetIfAsync(false); }as i mentioned before , it work perfectly as a normal plugin , when i change to the widget , nothing is displayed when i comment out the set function in controller , the box widget displayed normally . The reason it works when you comment out $this->set("data", $data); is because $data is undefined in index(), and attempting to reference it generates a php error. Quote
Blesta Addons Posted July 17, 2014 Author Report Posted July 17, 2014 Thanks Tyson for your reply That means that you are attempting to reference $this->Record, but that component has not been loaded. I think your widget should be created with a $render_section set for AJAX support: The components is loaded in my_plugin.php $this->Widget->create($this->_("MyprivateNotesPlugin.notes.heading_notes", true), array('id'=>"widget_myprivate_notes_admin_main", $this->Html->ifSet($render_section, null))); that what it was in the begin , and i have changed it and back it withot any result The reason it works when you comment out $this->set("data", $data); is because $data is undefined in index(), and attempting to reference it generates a php error. i have defined in several ways , without success to make it work $data = new stdClass(); and $data = array(); who he will make me crazy , is that the same code is working in a page without any probleme . when i change it to a widget nothing is displayed ?! Quote
Tyson Posted July 18, 2014 Report Posted July 18, 2014 You'll need to keep the $render_section in there. Have you checked the response sent back to your browser after the widget is fetched? There may be an error shown in the response, which could be why the widget is not displayed. Quote
Blesta Addons Posted July 18, 2014 Author Report Posted July 18, 2014 You'll need to keep the $render_section in there. Have you checked the response sent back to your browser after the widget is fetched? There may be an error shown in the response, which could be why the widget is not displayed. no response sent , is like no widget rendered , for that ihave asked for a debug code to make me show the eror code or response codes . the widget is not rendered at all , normally is should display the box with the widget title ? when i play with just a normal text it work perfectly . Quote
Tyson Posted July 18, 2014 Report Posted July 18, 2014 Does your widget appear in the "Manage Widgets" section of the dashboard or billing overview pages? Did you remember to define an action for it in MyprivateNotesPlugin::getActions()? You can always take a look at other plugins that define widgets, if you haven't already. Quote
Blesta Addons Posted July 18, 2014 Author Report Posted July 18, 2014 Does your widget appear in the "Manage Widgets" section of the dashboard or billing overview pages? Did you remember to define an action for it in MyprivateNotesPlugin::getActions()? You can always take a look at other plugins that define widgets, if you haven't already. Hello Tyson is already defined and it appear in "Manage Widgets" section . the widget content appear when i use a static output . but when i work with arrays and database , not working . the same code in controller and model work fine in normal output page plugin , but no in widget . Quote
Tyson Posted July 19, 2014 Report Posted July 19, 2014 Hello Tyson is already defined and it appear in "Manage Widgets" section . the widget content appear when i use a static output . but when i work with arrays and database , not working . the same code in controller and model work fine in normal output page plugin , but no in widget . If it works without setting arrays or querying the database, then I suspect the issue could be with the models you're loading or the data you're setting, which causes an error. To see what the error is, you can take a look at the php logs, or check the AJAX response in the browser when it fails to display the widget content. Blesta Addons 1 Quote
Blesta Addons Posted July 19, 2014 Author Report Posted July 19, 2014 Hello Tysonis models issue/probleme . what i have do .i have load the Staff model and i have tested with get function and it waorked like a charm .i have copied the same function in my models and i have loaded it and no result .i believe i have made a mistake in somewhere but really i have see and see and i can't find from where is the probleme .i have created a staff_notes.php in models . the content are class GetStaffNotes extends StaffNotesModel { /** * Initialize */ public function __construct() { parent::__construct(); // Load required components/helpers Loader::loadComponents($this, array("Input", "Record")); } public function GetStaffNotes($staff_id, $company_id=null) { $fields = array("staff.id", "staff.user_id", "staff.first_name", "staff.last_name", "staff.email", "staff.email_mobile", "staff.status", "users.username", "users.two_factor_mode", "users.two_factor_key", "users.two_factor_pin" ); $staff = $this->Record->select($fields)->from("staff")-> innerJoin("users", "users.id", "=", "staff.user_id", false)-> where("staff.id", "=", $staff_id)->fetch(); // Assign object properties only if staff exists if ($staff) { // Get the staff groups this staff member belongs to $this->Record->select(array("staff_groups.id", "staff_groups.company_id", "staff_groups.name"))-> from("staff")-> innerJoin("staff_group", "staff_group.staff_id", "=", "staff.id", false)-> innerJoin("staff_groups", "staff_group.staff_group_id", "=", "staff_groups.id", false)-> where("staff.id", "=", $staff_id); // Get a single or multiple groups depending on company if ($company_id) $staff->group = $this->Record->where("staff_groups.company_id", "=", $company_id)->fetch(); else $staff->groups = $this->Record->fetchAll(); if ($company_id !== null) $staff->settings = $this->getSettings($staff_id, $company_id); // Set staff email notices $staff->notices = $this->getNotices($staff_id); } return $staff; } } the controle file i have in it class AdminMain extends StaffNotesController { /** * Pre-action */ public function preAction() { parent::preAction(); $this->requireLogin(); Language::loadLang("staff_notes_plugin", null, PLUGINDIR . "staff_notes" . DS . "language" . DS); $this->plugin_id = (isset($this->get[0]) ? $this->get[0] : null); // Set the company ID $this->company_id = Configure::get("Blesta.company_id"); $this->staff_id = $this->Session->read("blesta_staff_id"); $this->user_id = $this->Session->read("blesta_id"); } /** * Renders the system overview widget */ public function index() { // Only available via AJAX if (!$this->isAjax()) { $this->redirect($this->base_uri); } $this->uses(array("StaffNotes.StaffNotes")); $staff = $this->GetStaffNotes->GetStaffNotes($this->staff_id , $this->company_id ); // $staff = $this->Staff->get($this->staff_id , $this->company_id ); // load from staff model $this->set("staff", $staff); return $this->renderAjaxWidgetIfAsync(isset($this->get[0]) ? false : null); } } the plugin dir is staff_notes .can you se any abnormal code in this two file ? Quote
Blesta Addons Posted July 21, 2014 Author Report Posted July 21, 2014 If it works without setting arrays or querying the database, then I suspect the issue could be with the models you're loading or the data you're setting, which causes an error. To see what the error is, you can take a look at the php logs, or check the AJAX response in the browser when it fails to display the widget content. resolved probleme with this step , but i don't know why !!! in model i have changed the class name to class StaffNotes extends StaffNotesModel in controllers i have changed this lines from $this->uses(array("StaffNotes.StaffNotes")); $staff = $this->GetStaffNotes->GetStaffNotes($this->staff_id , $this->company_id ); to $this->uses(array("staff_notes.StaffNotes")); $staff = $this->StaffNotes->getNotes($this->staff_id, $this->company_id); Quote
Tyson Posted July 21, 2014 Report Posted July 21, 2014 While I can't tell you exactly why you had this problem, I can say there are a couple problems with the code you had written. Hello Tysonis models issue/probleme . what i have do .i have load the Staff model and i have tested with get function and it waorked like a charm .i have copied the same function in my models and i have loaded it and no result .i believe i have made a mistake in somewhere but really i have see and see and i can't find from where is the probleme .i have created a staff_notes.php in models . the content are class GetStaffNotes extends StaffNotesModel { /** * Initialize */ public function __construct() { ... } public function GetStaffNotes($staff_id, $company_id=null) { ... } } Here, you have two constructors for the class. I don't know how PHP handles an instance of a constructor and a constructor by name, but I'd guess it could be a source of the problem. You should only use __construct(). More on this in the style guide. resolved probleme with this step , but i don't know why !!!in model i have changed the class name to class StaffNotes extends StaffNotesModel in controllers i have changed this lines from $this->uses(array("StaffNotes.StaffNotes")); $staff = $this->GetStaffNotes->GetStaffNotes($this->staff_id , $this->company_id ); to $this->uses(array("staff_notes.StaffNotes")); $staff = $this->StaffNotes->getNotes($this->staff_id, $this->company_id); The proper use of loading a model and calling it is: $this->uses(array("PluginName.ModelName")); $var = $this->ModelName->modelMethod($arg1, $arg2, ...); You may want to re-evaluate your naming conventions. For instance, I might name the plugin StaffNotes, and create a model Notes, with a method get. Thus, $this->uses(array("StaffNotes.Notes")); $notes = $this->Notes->get($this->staff_id); I don't see a need to include the company ID, as you can simply use the company already set in Blesta as referenced with Configure::get("Blesta.company_id"); Also, you don't need to load the Input and Record components from your model, since it inherits that from AppModel. Quote
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.