Blesta Addons Posted July 21, 2014 Report Posted July 21, 2014 is there any tips or raod to call a blesta function from the template file ? or at least from a php file inside the template ? Quote
Tyson Posted July 21, 2014 Report Posted July 21, 2014 You shouldn't be calling php functions from template files. That is contrary to the MVC design and breaks the separation of business logic from presentation. Any data that should be available to a template should be set by the controller. Quote
Blesta Addons Posted July 21, 2014 Author Report Posted July 21, 2014 so i shold create a plugin and work with it ? i want to use some custom 'let say widgets' for theme . so is not possible at all to do that . for example i want to make a ajax request for login . normally if i call the login page http://xxxxx.com/blesta/client/login/ with ajax i get a html response and i want ji*ust a true/false reponse , i should create a custom page in php to handel this , no ? Quote
Tyson Posted July 22, 2014 Report Posted July 22, 2014 Why do you want to make an AJAX request to login? Why not use the API? Quote
Blesta Addons Posted July 22, 2014 Author Report Posted July 22, 2014 i have in my new theme a portal system and it having a div box for login , i want to add a ajax request with login , if the login is corrected the box is updated with some client info . also in some area i want to push some info from database that are not available (or i have not looked well at the data available for templete . the important thing is i have some php function that show some data based in the client IP and client Email . so i want to pass the client_id and client_email to this file n and this file return me a response , this is possible with blestaRequest ajax , but what is not possible is how that file (located in templete folder load or communicated with other models in blesta ? Quote
Blesta Addons Posted July 22, 2014 Author Report Posted July 22, 2014 Real case now ; i want to get the last vist for client X and put it in the PDT file . i dont see any request/response to this record in the template . EDIT i get it with $client->date_added Now it left date_updated (last visit ) Quote
Tyson Posted July 22, 2014 Report Posted July 22, 2014 I don't know where you got the date_added property from, but you should be calling Logs::getUserLog($user_id) if you want to know the last time a user was active. Quote
Blesta Addons Posted July 22, 2014 Author Report Posted July 22, 2014 I don't know where you got the date_added property from, but you should be calling Logs::getUserLog($user_id) if you want to know the last time a user was active. yes Tyson ; i have this $clients->date_added and it show the date registration in template file i can call this function from template Logs::getUserLog($user_id) ? Quote
Tyson Posted July 22, 2014 Report Posted July 22, 2014 Now it left date_updated (last visit ) If you want to know the last time the user was active in the system (last visit), then call Logs::getUserLog($user_id) from the API or your plugin. Quote
Blesta Addons Posted July 22, 2014 Author Report Posted July 22, 2014 i'm not talking about API or plugin . i want to do this via template files , i want to make request to database from template file . for exemple , inside the template file client_main_myinfo.pdt , i want to do something like Welcome Back <strong><?php echo $this->Html->_($client->first_name, true) . " " . $this->Html->_($client->last_name, true);?></strong> Member Sinse <small><?php $this->Html->_($client->date_added);?></small> , Last Visit <small> <?php HERE_WHAT_SHOULD_I_PUT_I_CODE_TO_MANUPULATE_DATABASE ?></small> calling class from template file give a error "class not found" . Quote
Tyson Posted July 22, 2014 Report Posted July 22, 2014 You can't access the database from template files. There are several (hopefully obvious) reasons why you cannot. To fetch information that is not available to the template, you will need to update the controller to make it available. Quote
Blesta Addons Posted July 22, 2014 Author Report Posted July 22, 2014 You can't access the database from template files. There are several (hopefully obvious) reasons why you cannot. To fetch information that is not available to the template, you will need to update the controller to make it available. Thanks . is clear now , we should stop thinking about adding data to the templete files . with this situation we can't do more with template system . i think a feature request for something semilar should be done Quote
Blesta Addons Posted July 24, 2014 Author Report Posted July 24, 2014 You can't access the database from template files. There are several (hopefully obvious) reasons why you cannot. To fetch information that is not available to the template, you will need to update the controller to make it available. what about helpers ? is possible to include them in template , then i use helpers to retch database ? Quote
Tyson Posted July 24, 2014 Report Posted July 24, 2014 Helpers can be available to templates, but none perform database actions, nor should they. Helpers are geared toward formatting, which is useful for display purposes, and is why they can be used in views. With any MVC framework, there is a logical design separation between Models, Views, and Controllers. Business logic, like database queries, are in the models, and views do not access models--they only get data by way of their controller. So like I mentioned above, the correct way to go about getting data for a view is to update the controller to make it available to the view. Quote
Blesta Addons Posted July 24, 2014 Author Report Posted July 24, 2014 Thanks tyson for clarification . our probleme is that we don't want to hack or change the core files . Quote
Tyson Posted July 25, 2014 Report Posted July 25, 2014 Thanks tyson for clarification . our probleme is that we don't want to hack or change the core files . I can understand that. But Blesta does not make data available to views that it doesn't use, since that would be a waste of resources. It sounds like your template customizations need to be supported through a plugin instead, but since you don't want to use a plugin, there is no proper alternative than to change core files to do what you want. That said, I would not recommend anyone do this for reasons already mentioned, but you could technically load a model in the view and call it: $obj = new stdClass(); Loader::loadModels($obj, array("Clients")); $client = $obj->Clients->get(1); Blesta Addons 1 Quote
Blesta Addons Posted July 25, 2014 Author Report Posted July 25, 2014 It sounds like your template customizations need to be supported through a plugin instead, but since you don't want to use a plugin,... That said, I would not recommend anyone do this for reasons already mentioned, but you could technically load a model in the view and call it: using a plugin was our final raod to take . if i use a plugin , i can make the controller send the data to any view file without going to the url plugin ? for example when we access the page http://xxxx.xxx/blesta/client/main/ , we can load data from the plugin controller XXXX . ( as i know the controller send data to template file when is reached as url ( http://xxxx.xxx/blesta/admin/plugin/xxxxx/admin_main/ ) ? our last solution was the fallowing 1 - create plugin 2 - set fonction in controller to send a specific data like - http://xxxx.xxx/blesta/admin/plugin/request_ajax/totalservice/ - http://xxxx.xxx/blesta/admin/plugin/request_ajax/lastvisit/ - http://xxxx.xxx/blesta/admin/plugin/request_ajax/totalopenticket/ 3 - call this function with blestarequest ajax . Thanks 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.