i am using joomla 2.5 and install component community builder with work properly, and on the customize field i am add some field cb_nip, how to i get and show values cb_nip from php from user login, because i need values cb_nip for custom condition for me.
i tried get cb_nip values with script, but nothing shown anything :
$user = JFactory::getUser();
$cb_nip = JUserHelper::getProfile($user->cb_nip);
echo $comprofiler->comprofiler['cb_nip'];
please help me for this.
You need to query the database to do this.
$user = JFactory::getUser();
$db = $this->getDbo();
$query = 'SELECT cb_nip FROM #__comprofiler WHERE user_id='.$user->id;
$db->setQuery($query);
$cb_nip = $db->loadResult();
echo $cb_nip;
Related
I am trying to pass a users comment that they have posted into the thread to be displayed when they click the submit button on the create comment form. But the comment doesn't show up without refreshing the page (which also duplicates the comment). This is why I am trying to achieve this using redirect which I am finding difficult.
Currently in my controller i have the following code..
...
$query = 'SELECT * FROM thread where id='.$id;
$data['thread'] = $this->db->query($query)->result_array();
$query2 = 'SELECT username FROM newUsers where id='.$userid;
$data ['username'] = $this->db->query($query2)->result_array();
$query3 = 'SELECT id FROM newUsers where id='.$userid;
$data ['userid'] = $this->db->query($query3)->result_array();
$query4 = 'SELECT * FROM comments where thread_id='.$id;
$data['comment'] = $this->db->query($query4)->result_array();
I displayed this data in my view and all works fine with the following method....
$this->load->view('header', $data);
$this->load->view('discussion/create');
$this->load->view('footer');
The problem I faced was the comment not appearing when the page loaded.. I know i have to use the following
redirect('postComment/post','refresh');
In my controller/method, i have the following method
$this->load->view('header');
$this->load->view('discussion/create');
$this->load->view('footer2');
Im currently trying to pass this data with flash data which i'm not sure if its the best way.. i'm using the following code for this..
$this->session->set_flashdata('thread', $data['thread']);
$this->session->set_flashdata('username', $data['username']);
$this->session->set_flashdata('userid', $data['userid']);
$this->session->set_flashdata('comment', $data['comment']);
In the view I am trying to set the data the following way..
$data['thread'] = $this->session->flashdata('thread');
$data['comment'] = $this->session->flashdata('comment');
$data['username'] = $this->session->flashdata('username');
$data['userid'] = $this->session->flashdata('userid');
To display the data i am using the following..
foreach($thread as $t):
$t['id'];
$t['thread_title'];
$t['subject'];
$t['content'];
$t['created'];
$t['votes'];
endforeach;
I get multiple undefined variables and Invalid argument supplied for foreach().. Any help for my problem would be greatly appreciated
Flashdata is only for temporary things and will only work on page refresh once. You could use set_userdata() and just set the variables as a regular session variable, then when you are done with them you can unset them.
However I think it would be prudent to look into why you are doing this with session variables rather than getting the database rows on-the-fly. As you database tables get larger this will eventually be problematic.
I am upgrading a website from 1.5 to 2.5 which is used by different clients. To make sure to display the correct menues and modules I need to make a custom query in a system plugin when loading the page.
How can I set my query to the global dbo? I need to add a few lines so that the query also gets in the standard query in menu.php for example.
Here is my code:
$db = JFactory::getDbo();
$query = $db->getQuery();
$query->leftJoin("#__menu_types AS mt ON m.menutype = mt.menutype");
$query->leftJoin("#__wl_clientmap as cm on cm.target_id=mt.id AND cm.target_type='mnu'");
if ($this->clientid>0){
$query->where("cm.client_id=".intval($this->clientid)."");
}
else {
$query->where("(cm.client_id=0 OR cm.client_id IS NULL)");
}
$db->setQuery($query);
$menu = & JSite::getMenu();
and here is what's in includes/menu.php:
public function load()
{
// Initialise variables.
$db = JFactory::getDbo();
$app = JApplication::getInstance('site');
$query = $db->getQuery(true);
$query->select('m.id, m.menutype, m.title, m.alias, m.note, m.path AS route, m.link, m.type, m.level, m.language');
$query->select('m.browserNav, m.access, m.params, m.home, m.img, m.template_style_id, m.component_id, m.parent_id');
$query->select('e.element as component');
$query->from('#__menu AS m');
$query->leftJoin('#__extensions AS e ON m.component_id = e.extension_id');
$query->where('m.published = 1');
$query->where('m.parent_id > 0');
$query->where('m.client_id = 0');
$query->order('m.lft');
Sadly my custom query does not appear on menu.php's query. How can I make sure that it gets in?
You can hijack the database object the same way Joomfish does, roughly it works like this in a system plugin
$db = & JFactory::getDBO();
$db = new JFDatabase($options);
Then all queries go through your object and you can pass anything you don't want to change on to the normal database layer.
Have a look at jfrouter plugin in Joomfish to get some more ideas.
I've asked this question in the SugarCRM forums, but have been unable to find the answer as well. I am trying to populate a dropdown list in SugarCRM Community 6.5. I am using PHP5, MySQL and Apache. I created a custom dropdown list named 'oz_accounts' in the dropdown editor, created a new field in the custom module, Machines, that I built and associated the field with the Edit, Quick Create, Detail and List views based on the dropdown menu. Here is the code that I used, the result is a blank dropdown menu:
<?php
require_once('include/entryPoint.php');
$db = & DBManagerFactory::getInstance();
$myQuery = "SELECT name FROM accounts";
$Result = $db->query($myQuery);
$new_array = array();
while($row = $db->fetchByAssoc($Result)) {
$new_array[$row['key']] = $row['value'];
}
$GLOBALS['app_list_strings']['oz_accounts'] = $new_array;
Could someone please advise on what I'm doing incorrectly? I tested the query in phpmyadmin, and it retrieves the result i'm looking for, so I'm assuming that I must be making a mistake somewhere in the PHP code, possibly connecting to the database.
I posted directions on how to do this here some time ago: http://www.eggsurplus.com/content/populate-a-dropdown-from-the-database/
What you need to do is to create a custom util function and then tell your vardefs for that field to call the custom util function.
//custom/Extension/application/Ext/Utils/getAccounts.php
function getAccounts(){
static $accounts = null;
if(!$accounts){
global $db;
$query = "SELECT id, name FROM accounts";
$result = $db->query($query, false);
$accounts = array();
$accounts[''] = '';
while (($row = $db->fetchByAssoc($result)) != null) {
$accounts[$row['id']] = $row['name'];
}
}
return $accounts;
}
Name of the file doesn't matter. Make sure to include opening PHP tags. Run a Repair/Rebuild so that it builds custom/application/Ext/Utils/custom_utils.ext.php.
Then in the vardef definition for that field set the function to getAccounts:
'function' => 'getAccounts',
Repair/Rebuild will be needed after the vardef change.
the problems is in process definition the list not showing
I'm wondering if someone can give me a bit of a hand.
I'm trying to write a query inside a PHP file in Joomla and its not really working that well, nothing is being output.
I'm very new to this Joomla stuff, so if someone could let me know where I'm going wrong that would be great.
My code is as follows:
$db =& JFactory::getDBO();
$query = "SELECT fullname FROM jos_jxzine_authors WHERE published = '1'";
$db->setQuery($query);
$column = $db->loadResultArray();
echo JHTML::_('select.options', $column, 'value', 'text', $this->categoryMap);
Cheers,
Please use this query
$query = "SELECT fullname FROM `#__jxzine_authors` WHERE published = '1'";
joomla will itself add db prefix. So you must use #_ instead of jos
I have a couple of tables (mySQL) that i would like to update with the help of Doctrine. The products table id is auto-incrementing, and here's a brief description on what I would like to do:
$prod = new Products();
$prod->type = '0';
$categ = new CategoriesToProducts();
$categ->cat = '111';
$categ->product = $prod->id;
$conn = Doctrine_Manager::connection();
$conn->flush();
How can I do this while using flush? Using a regular save is an alternative, but there will be multiple transactions while doing such.
I have tried to find a Mysql_insert_id version for doctrine, but without any luck.
Thanks!
Here you can find some information: http://www.doctrine-project.org/documentation/manual/2_0/en/basic-mapping#identifiers-/-primary-keys