Archive for the ‘Joomla’ Category

Connecting Joomla to database

preparing the query

// Get a database object
$db = JFactory::getDBO();

$query = "SELECT * FROM #__example_table WHERE id = 999999";
$db->setQuery($query);

of course using the Database

Basic Query Execution

- query (This should be user after Set Query if you want to use getNumRows)

Query Execution Information

- getAffectedRows
-explain
-insertid

Insert Query Execution
-insertObject

Single Value Result

-loadResult

Single Row Results

-loadObject
-loadRow
-loadResultArray

Multi-Row Results

-loadObjectList
-loadRowList
-loadAssocList

Misc Result Set Methods

-getNumRows

a nice code would go like

$database = JFactory::getDBO();
$user_name=$_POST['username'];
$query = "SELECT * FROM #__users";
$database->setQuery($query);
$existing_users=$database->loadResultArray();
if (in_array($user_name, $existing_users)) {.. do something }
            

Class ‘JFactory’ not found

yes the first thing that happened to when I tried to connect joomla page to database was this line. and I couldnt figure our what happened until I realized that I cant make a raw php page and make a connection to database usually I should set all php into the controller.php for the component in a function and if I want to request that function the URL should go in something like :

http://localhost/joomla/index.php?option=com_user&format=raw&view=register&task=user_availability

- option is the current component
- raw is to request a plain page without the template design
- view : is what you are currently viewing
- task : is the function from the controller you want to run

Joomla – Horizontal Login

Just to make the login horizontal replace (you better backup the replaced file) the following file with the attachement :

modules/mod_login/tmpl/default.php

Download the file Here : default.zip

Adding New Positions to Joomla

Yes, another thing I thought would be complicated and be surprised of its simplicity
just open the XML of the the current template and add the positions you want

<positions>
<position>hornav</position>
<position>breadcrumbs</position>
<position>banner</position>
<position>left</position>
<position>right</position>
<position>top</position>
<position>search</position>
<position>topsl</position>
<position>user1</position>
<position>user2</position>
<position>user3</position>
<position>user4</position>
<position>user5</position>
<position>user6</position>
<position>user7</position>
<position>user8</position>
<position>user9</position>
<position>footer</position>
<position>syndicate</position>
<position>debug</position>
</positions>

Joomla Page Title inside body

Wow, I searched for this for so long >.<
Tried
“Joomla Custom title”
“Joomla Page Title”
“Joomla Title in divs”
and so and so on o__o the good news its one line answer!!
ok here it is

<?php echo $mainframe->getPageTitle(); ?>

Basic Reminder of how to create Joomla Component

Front End : Lets assume our component is called gold

1- Create a sub folder for the component folder call it com_gold

2- Create a file called gold.php inside of it (Known as Entry Point)

<?php
defined(‘_JEXEC’) or die(‘Restricted access’);

require_once( JPATH_COMPONENT.DS.‘controller.php’ );

if($controller = JRequest::getWord(‘controller’)) {

$path = JPATH_COMPONENT.DS.‘controllers’.DS.$controller.‘.php’;

if (file_exists($path)) {

require_once $path;

} else {

$controller = ;

}

}

$classname = ‘goldController’.$controller;

$controller = new $classname( );

$controller->execute( JRequest::getVar( ‘task’ ) );

$controller->redirect();

?>
?>

Back End :

1- Create a sub folder for the administrator/components folder call it com_gold

2- Create a file called admin.gold.php inside of it

Now you can Access the Component

http://localhost/joomla/index.php?option=com_gold

——————

Adding :

1- Controller to Front End : The controller is responsible for responding to user actions

create a file called controller.php inside com_gold

<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.application.component.controller');
class GoldController extends JController
{
    function display()
    {
        parent::display();
    }

}
?>

2- View to Front End : part of the component that is used to render the data from the model in a manner that is suitable for interaction

create views/gold/gold.html.php inside com_gold

<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.view');
class GoldView extends JView
{
    function display($tpl = null)
    {
        $sentence = "Gold Component";
        $this->assignRef( 'sentence', $sentence );

        parent::display($tpl);
    }
}
?>

2- Template to Front End :

create views/gold/tmpl/default.php inside com_gold

<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<h1><?php echo $this->greeting; ?></h1>


Return top

INFORMATION

Change this sentence and title from admin Theme option page.