Welcome, Guest. Please login or register.
Did you miss your activation email?
May 26, 2012, 05:28:21 PM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
155544 Posts in 21714 Topics by 7736 Members
Latest Member: chris85
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Does snippets work in backend ?  (Read 742 times)
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« on: April 16, 2011, 03: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

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #1 on: April 16, 2011, 04: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:
<?php
$my_snippet 
WB_PATH.'/modules/my_snippets_directory/include.php';
if(
file_exists($my_snippet){
 require_once(
$my_snippet);
}

Kind regards,
Stefek
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #2 on: April 21, 2011, 01:56:04 PM »

Cool, but have another problem..

For example if I have this lame function:
Code:
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 Huh

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

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

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #3 on: April 21, 2011, 03: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

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
BlackBird
AddOn Development
*
Offline Offline

Posts: 2069



WWW
« Reply #4 on: April 21, 2011, 03:07:10 PM »

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

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

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

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

Logged

Alle großen Veränderungen beginnen im Kleinen
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #5 on: April 21, 2011, 08: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

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
BlackBird
AddOn Development
*
Offline Offline

Posts: 2069



WWW
« Reply #6 on: April 23, 2011, 01:35:32 PM »

The code I posted should solve this.
Logged

Alle großen Veränderungen beginnen im Kleinen
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« Reply #7 on: April 24, 2011, 08:17:27 PM »

whohoo it works Smiley

thanks BB !!
Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!