We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

Simple code for plugin | Forum

Kenneth
Kenneth Dec 9 '11
Hi

I just need a very simple code for my controllers. This is what I need:


select email from table where userid = $userid.

How can I put this in code? I only need to draw the email from a table.

I have the following function
class BANNERS14_CTRL_Banner14 extends OW_ActionController { public function index() { $this->setPageTitle(OW::getLanguage()->text('banners14', 'index_page_title')); $this->setPageHeading(OW::getLanguage()->text('banners14', 'index_page_heading')); $userId = OW::getUser()->getId(); $this->assign('list', $list); } private function text( $prefix, $key, array $vars = null ) { return OW::getLanguage()->text($prefix, $key, $vars); } }
Kenneth
Kenneth Dec 10 '11
Really nobody who can help me? I can php code, but just not the framework stuff..
Sardar
Sardar Dec 11 '11
Hello,

You can easily get user email using the common service.
Try the code below:

$user = BOL_UserService::getInstance()->findUserById($userId);
$email = $user->getEmail();

Kenneth
Kenneth Dec 17 '11
Hi Sardar,

Thank you very much for your answer. I used another 4/5 hours to tried figuring it out, but with no lock.

I tried to put into an existingpuclic function index, but then I got the message that i was a non object function.
Then I made an new function, and no error occures on the page. But I can't get the "email" to be shown on the page.
I use the "contactus" script, on put it into the controller, and the index page. Am I missing something?

I attached the files, so you could se my problem. Look at file controllers/banner23.php Line 41. And file views/banner23_index.html Line 4 and 5.

I really just need to pull out the email and username from the database and show it as text in the index page.
The Forum post is edited by Kenneth Dec 17 '11
Attachments:
  banners23.zip (19.81Kb)
Kenneth
Kenneth Dec 17 '11
If someone helps me understand the userservice, and how to use it as explained above, I will make a controbution to the oxwall documentation. On this topic.

Thank you
Sardar
Sardar Feb 3 '12
Kenneth,
The code I provided is very simple and should work. The only thing you should provide is $userId. If you use wrong userId service will return NULL instead of object, that's why you have an error. Before getting the email check if object link is null.

Try this:
-------------------------------------
$user = BOL_UserService::getInstance()->findUserById($userId); 
if( $user != null )
{
     $email = $user->getEmail();
}
--------------------------------------

You just need to provide valid user id, here is an example of getting the id of current user:

-------------------------------------
if( OW::getUser()->isAuthenticated() )
{     
$userId = OW::getUser()->getId();
}
-------------------------------------
The Forum post is edited by Sardar Feb 3 '12
Michael I.
Michael I. Dec 21 '12
Topic was moved from Plugins.