Call to a member function getResultArray() on bool codeigniter 4 - codeigniter

I am gettin this error
Call to a member function getResultArray() on bool
in my pc run very good but in my hosting i have this error
What can I do? help me please
'public function obt_lista_prestamos($activo)
{
$db = \Config\Database::connect();
$db = db_connect();
$builder = $db->table('t_prestamo');
$builder->select('*');
$builder->join('t_clientes', 't_prestamo.fk_idcliente = t_clientes.id_cliente');
$query = $builder->get();
$query = $query->getResultArray();
return ($query);
}'

your code seems fine, but you can try with this:
'public function obt_lista_prestamos($activo)
{
$db = \Config\Database::connect();
$db = db_connect();
$builder = $db->table('t_prestamo');
$builder->select('*');
$builder->join('t_clientes', 't_prestamo.fk_idcliente =
t_clientes.id_cliente');
$query = $builder->get()->getResultArray();
return ($query);
}'
I had the same problem and this worked for me.
Note this line: $query = $builder->get()->getResultArray();

Related

Need to get samaccountname and name/cn laravel ldap-record

My code so far:
public function getClerks() {
$group = Group::find('CN=Clerks Internet,OU=Clerks,OU=Department,DC=mydomain,DC=com');
$members = $group->members()->get(); //->flatten()->all();
dd($members);
}
Need to get samaccountname and name/cn from the laravel collection that this gives.
The Collection:
I found my own answer.
public function getClerks() {
$group = Group::find('CN=Clerks Internet,OU=Clerks,OU=Department,DC=domain,DC=com');
$members = $group->members()->get();
$keySearch = "samaccountname";
$membersList = $members->toJson();
$jsonObj = json_decode($membersList);
$accounts = array_column($jsonObj,$keySearch);
foreach($accounts as $account){
echo $account[0]."<br>";
}
}

laravel error "strtolower() expects parameter 1 to be string"?

I am passing json to a laravel route as following and I am runnig this query sql view.
{"columns":["fname","lname","mobile"], "offset":"1", "limit":"25",
"order":[["fname","asc"],["lname","asc"]],
"filter":[["gender","=","M"]]}
And this is the function placed in controller which will going to call on route
public function fetch_contacts(Request $request){
if($request->header('content-type') == 'application/json' && !empty($request->header('Device')) && !empty($request->header('UID'))){
$query = DB::connection('mysql_freesubs')->table("contact_view")
->select($request->columns);
if(!empty($request->filter))
$query = $query->where($request->filter);
if(!empty($request->offset))
$query = $query->offset($request->offset);
if(!empty($request->limit))
$query = $query->limit($request->limit);
if(!empty($request->order))
$query = $query->orderBy($request->order);
$contacts = $query->get();
return $contacts;
}
where am I going wrong ?
You're passing multidimensional array to orderBy, try this instead:
$query = $query->orderBy($request->order[0][0], $request->order[0][1]);
$query = $query->orderBy($request->order[1][0], $request->order[1][1]);

Joomla 2.5 pagination

I want to add pagination to my component, i've created a simple model with query. I must be missing something. What else do I need here ?
MODEL
jimport('joomla.application.component.modellist');
class PaieskaModelPradinis extends JModelList
{
public function getListQuery()
{
$db = JFactory::getDBO();
$query = "SELECT * FROM #__content";
$db->setQuery( $query );
$db->query( $query );
$result = $db->LoadObjectList();
return $result;
}
}
VIEW
jimport( 'joomla.application.component.view');
class PaieskaViewPradinis extends JView
{
protected $items;
protected $pagination;
function display ($tpl = null)
{
$this->items = $this->get('ListQuery');
$this->pagination = $this->get('Pagination');
parent::display($tpl);
}
}
TPL
foreach ($this->items as $item) {
echo $item->title;
}
EDITED:
I edited a bit code, so now it works fine, almost. Button display(number of rows to display) is not working. And I wonder if this part can be done in a different way ?
$limit = JRequest::getVar('limit' , 25);
$start = JRequest::getVar('start' , 0);
$query = "SELECT * FROM #__content LIMIT $start, $limit";
-
class PaieskaModelPradinis extends JModelList
{
public function getItems()
{
$db = JFactory::getDBO();
$limit = JRequest::getVar('limit' , 25);
$start = JRequest::getVar('start' , 0);
$query = "SELECT * FROM #__content LIMIT $start, $limit";
$db->setQuery( $query );
$db->query( $query );
$lists = $db->LoadObjectList();
return $lists;
}
function getPagination()
{
$main = JFactory::getApplication();
$db = JFactory::getDBO();
$limit = JRequest::getVar('limit' , 25);
$limitstart = JRequest::getVar('limitstart', 0);
$query = "SELECT count(title) FROM #__content";
$db->setQuery( $query );
$total = $db->loadResult();
// include a pagination library
jimport('joomla.html.pagination');
$pagination = new JPagination($total, $limitstart, $limit);
return $pagination;
}
}
VIEW
jimport( 'joomla.application.component.view');
class PaieskaViewPradinis extends JView
{
function display($tpl = null)
{
$this->items = $this->get('items');
$this->pagination = $this->get('pagination');
parent::display($tpl);
}
}
Going off your original code, not the edited version.
The getListQuery method only builds your database query, so you don't execute your query here. Use com_weblinks as an example for building out your model: https://github.com/joomla/joomla-cms/blob/2.5.x/components/com_weblinks/models/category.php
follow this link http://docs.joomla.org/J1.5:Using_JPagination_in_your_component properly.
I have used Joomla pagination. You'll be able to use Joomla pagination easily, if you follow documentation properly. BTW its very simple.

Joomla 2.5 database $query->where warning

I have this simple code to select custom string from database:
protected function getListQuery()
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*')
->from('#__person');
$name = 'tom';
$query->where('name LIKE %'.$db->quote($name).'%');
return $query;
}
Unfortunately it gives me an error:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean
given in xxx\public\libraries\joomla\database\database\mysql.php on
line 293
If I remove where call, so everything goes ok. Can I debug the datase query? I would like to see whats the final query goes to MySQL server.
Your help would be appreciated.
I've managed to work this for me:
protected function getListQuery()
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*')
->from('#__person');
$name = 'tom';
$name = $db->Quote('%'.$db->escape($name, true).'%');
$query->where($db->nameQuote('name').' LIKE '.$name);
//debug the query
// echo nl2br(str_replace('#__','prefix_',$query)); die;
return $query;
}

joomla loadformdata

how to show data from 3 tables in one view, because using JTable i can show data only bind to that JTable, please help me with this one.
my code so far(not working) in models:
public function getEntireProject(){
$item_id = $this->getItem()->id;
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__project_part_1 AS a');
$query->leftJoin('#__project_part_2 AS u ON a.uuid = u.uuid');
$query->leftJoin('#__project_part_3 AS y ON a.uuid = y.uuid');
$query->where('a.id = '. (int) $item_id);
$db->setQuery($query);
return $db->loadResult();
}
protected function loadFormData()
{
// Check the session for previously entered form data.
$data = JFactory::getApplication()->getUserState('com_web_projects.edit.webproject.data', array());
if (empty($data)) {
$data = $this->getEntireProject();
}
return $data;
}
try to overwrite getItem function.This will also be helpful if you are calling get('Item') in view. -
public function getItem($pk = null){
if ($item = parent::getItem($pk)) {
$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('*');
$query->from('#__project_part_1 AS a');
$query->leftJoin('#__project_part_2 AS u ON a.uuid = u.uuid');
$query->leftJoin('#__project_part_3 AS y ON a.uuid = y.uuid');
$query->where('a.id = '. (int) $item->id);
$db->setQuery($query);
$item = $db->loadAssoc();
}
return $item;
}
protected function loadFormData()
{
// Check the session for previously entered form data.
$data = JFactory::getApplication()->getUserState('com_web_projects.edit.webproject.data', array());
if (empty($data)) {
$data = $this->getItem();
}
return $data;
}
For Multi-Row Results use loadRowList(), loadAssocList(), loadAssocList($key), loadObjectList(), loadObjectList('key'). $db->loadResult() only load one result. Read more.
If I understand your question right this should fix your problem. If you not please ask.

Resources