Does snippets work in backend ?

crnogorac081

Web developer

BlackBird

The code I posted should solve this.
[url=http://wbaddons.webbird.de]http://wbaddons.webbird.de[/url] [url=http://www.WebsiteBaker.org/forum/index.php/topic,27476.msg189845.html#msg189845]Don't miss this[/url]

crnogorac081

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
Web developer

BlackBird

Before including the snippet, try to add this to your code:


global $wb;
if ( ! is_object($wb) ) {
  $wb =& $admin;
}


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


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

[url=http://wbaddons.webbird.de]http://wbaddons.webbird.de[/url] [url=http://www.WebsiteBaker.org/forum/index.php/topic,27476.msg189845.html#msg189845]Don't miss this[/url]

Stefek

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


[i]"Gemeinsam schafft man mehr."[/i]

[b][url=http://duden.de/rechtschreibung/gemeinsam#Bedeutung1]gemeinsam[/url][/b]
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

crnogorac081

#3
Cool, but have another problem..

For example if I have this lame function:

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
Web developer

Stefek

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
<?php
$my_snippet 
WB_PATH.'/modules/my_snippets_directory/include.php';
if(
file_exists($my_snippet){
 require_once(
$my_snippet);
}


Kind regards,
Stefek
[i]"Gemeinsam schafft man mehr."[/i]

[b][url=http://duden.de/rechtschreibung/gemeinsam#Bedeutung1]gemeinsam[/url][/b]
1. mehreren Personen oder Dingen in gleicher Weise gehörend, eigen
2. in Gemeinschaft [unternommen, zu bewältigen]; zusammen, miteinander
#Duden

crnogorac081

Hi,

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

cheers
Web developer