WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.8 is now available!


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker

Your donations will help to:

  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!

You can donate by clicking on the button below.


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Does snippets work in backend ?
  • Print
Pages: [1]   Go Down

Author Topic: Does snippets work in backend ?  (Read 8036 times)

Offline crnogorac081

  • Posts: 2163
  • Gender: Male
Does snippets work in backend ?
« on: April 16, 2011, 04:53:57 PM »
Hi,

are snippets loaded to backend or is there a way to load it manualy? I get error: Call to undefined function ...

cheers
Logged
Web developer

Offline Stefek

  • Posts: 6177
  • Gender: Male
  • ("ړ)
Re: Does snippets work in backend ?
« Reply #1 on: April 16, 2011, 05:00:36 PM »
Hello Ivan,

no they don't.

If you want to use a specific function of a snippet in Backend, you will need to include it into your php-script.

Like
Code: [Select]
<?php
$my_snippet 
= WB_PATH.&#39;/modules/my_snippets_directory/include.php&#39;;
if(file_exists($my_snippet){
 require_once(
$my_snippet);
}

Kind regards,
Stefek
Logged
"Gemeinsam schafft man mehr."

gemeinsam
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

Offline crnogorac081

  • Posts: 2163
  • Gender: Male
Re: Does snippets work in backend ?
« Reply #2 on: April 21, 2011, 02:56:04 PM »
Cool, but have another problem..

For example if I have this lame function:
Code: [Select]
function thisFunction($user) {
global $database, $wb;
...
$to_user = $wb->add_slashes($user);
return $to_user;
}
In snippet I have $wb->add_slashes($something); and when I use it in backend I get: Fatal error: Call to a member function add_slashes() on a non-object in ---- line where I use $wb->add_slashes

How can I redeclare snippet to use $admin in backend instead $wb ???

Or is there another way that same function works in FE and BE

cheers
« Last Edit: April 21, 2011, 03:24:45 PM by crnogorac081 »
Logged
Web developer

Offline Stefek

  • Posts: 6177
  • Gender: Male
  • ("ړ)
Re: Does snippets work in backend ?
« Reply #3 on: April 21, 2011, 04:02:03 PM »
Hello Ivan,

I only have an Idea on how you could make it, but I am sure that there is a better approach to this than mine.

What about writing a second function for the backend instead of using the same in both places (FE/BE)?

Regards,
Stefek


Logged
"Gemeinsam schafft man mehr."

gemeinsam
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

Offline BlackBird

  • Posts: 2573
Re: Does snippets work in backend ?
« Reply #4 on: April 21, 2011, 04:07:10 PM »
Before including the snippet, try to add this to your code:

Code: [Select]
global $wb;
if ( ! is_object($wb) ) {
  $wb =& $admin;
}

If this doesn't work, instantiate $wb yourself.

Code: [Select]
if ( ! is_object($wb) ) {
  require_once(WB_PATH.'/framework/class.frontend.php');
  $wb = new frontend();
}

Logged
http://wbaddons.webbird.de Don't miss this

Offline crnogorac081

  • Posts: 2163
  • Gender: Male
Re: Does snippets work in backend ?
« Reply #5 on: April 21, 2011, 09:03:44 PM »
It works fine in frontend, but backend is the problem.. I use $wb->add_slashes($something);  in frontend to sanitize values, but problem appears when I use function in BE.. tbecause then all $wb->SOMETHING needs to be replaced with $admin->SOMETHING
Logged
Web developer

Offline BlackBird

  • Posts: 2573
Re: Does snippets work in backend ?
« Reply #6 on: April 23, 2011, 02:35:32 PM »
The code I posted should solve this.
Logged
http://wbaddons.webbird.de Don't miss this

Offline crnogorac081

  • Posts: 2163
  • Gender: Male
Re: Does snippets work in backend ?
« Reply #7 on: April 24, 2011, 09:17:27 PM »
whohoo it works :)

thanks BB !!
Logged
Web developer

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Does snippets work in backend ?
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2