I want to modify a native joomla module that display articles of a category. I want it to display articles of an other prefix tables (both joomla website are on the same server).
Notice that I already looked at available extension but none of them would fit.
I tried to modify the helper.php of the native joomla module
tables, by changing the
$com_path =
but i am getting aFatal error.
Native code:
$com_path = JPATH_SITE.'/components/com_content/';
My try :
$com_path = '/homez.420/kmxsiksf/rsc/components/com_content/helpers/route.php
To use an external database (even if it's on your server) in Joomla extensions, the proper way would be to set some options before retrieving the JDatabase-object.
Create a helperclass to handle your external db, and in every method that uses the DB-object you simply set the options of your external db before retrieving the object:
$option = array();
$option['driver'] = 'mysql';
$option['host'] = 'localhost'; // In your case probably localhost
$option['user'] = 'dbusername'; // User for database authentication $option['password'] = 'badpass12345'; // Password for database authentication $option['database'] = 'bigdatabase'; // Database name
$option['prefix'] = 'abc_'; // Database prefix (may be empty)
$db = & JDatabase::getInstance( $option );
You are now able to use your external database the same way as you would with your regular db.
Related
I am getting timeout error and tried everything to change its value from 600 but now luck. Can any body help to do this for SugarCRM?
Instead of changing in SugarCRM configuration file config.php try to change in config_override.php. You can also add your custom configuration using module loader apply following code in manifest.php file.
$cfg = new Configurator();
// Your custom configuration code
$cfg->config['myaddon_setting'] = true; // This will make add-ons setting enable.
$cfg->handleOverride();
To Perform database queries use following code.
$mymodule = BeanFactory::newBean($module);
$db = DBManagerFactory::getInstance();
$query = "SELECT * FROM users WHERE 1";
$result = $db->query($query, true,"Error reading the database");
For logic hooks click on Logic Hooks. Write down in comment if you need anything else.
I am trying to find a way to run codeigniter from a sub-directory of another codeigniter installation. The CI from the sub-directory would be for testing and the main one is the live site. Anyone could advice on this or any other better approach ?
I believe you can just place this in the root folder and set the base url in the config :
$config['base_url'] = 'http://www.example.com/testsite/';
then it works.
There can be issues with the first application serving the 404 pages when a route is not matched however
I am posting the answer here, because is too long to use it as a comment...
I made it thru another approach: setting different $active_group in the config/database.php file.
So, first I have checked for a parameter in $_GET, if that is set we use a group, otherwise the default group (the other group is used for testing - a separate database, exact structure but without touching the main db)
if(!isset($_SESSION)){session_start();}
if (isset($_GET["debugmode"])){
$active_group = 'demodb';
$active_record = TRUE;
$_SESSION['debugmode'] = true;
}elseif (isset($_SESSION["debugmode"])){
$active_group = 'demodb';
$active_record = TRUE;
}elseif(!isset($_GET["debugmode"]) && !isset($_SESSION["debugmode"])){
$active_group = 'default';
$active_record = TRUE;
}
To make sure this will work on all the controllers /views, because we wont have that $_GET parameter all over the application, we can set that session value once we have that $_GET parameter present. Also, we have to make sure we destroy that session when we log out or after an amount of time.
Reason of using a Session value: by default CI is using that table to store the sessions, without using our session value, it will force somehow to use the default DB, or at least I couldn't find it to trick this step.
My custom component has to call the core content component and create an entry in the #__content table with proper values. When I add a new article in the article manger I have to give only a title as mandatory field value and other values will be created automatically. I want to pretend this in my custom component.
Instead of updating the database table directly load the ContentModelArticle from com_content and use the model to create new articles. This will generate the alias for you, do all of ACL etc based on the View Access and let any system or content plugins have a look at the article and do whatever they do.
ContentModelArticle extends from JModelAdmin so you can use it's ->save($data) method. Where $data is the array of content to bind to the new ContentModelArticle in the save() method.
So, a basic example would be :
// Create our data with some sample code
$data['title'] = 'My Title';
$data['catid'] = 10; /* NB. this is just an example category Id obviously you'll need to provide a suitable catid for your site */
$data['articletext'] = 'Starting text...'; /* From memory you can't have an empty article.*/
// Get the Article model
$articleModel = $this->getModel('Article', 'ContentModel', array());
// Then save it:
$articleModel->save($data);
Obviously you can populate as many fields as you want, including state, publish_up, publish_down, create_by and lots of others — just look at the structure of the content table in the database #__content to see the various columns and their type.
NB: This is untested code just typed into the browser. It's also been a while since I did any 2.x stuff.
Finally, as this question is about Joomla specific implementation details, you may get a better result if you, try asking on the Joomla Q&A StackExhange site
I really hope someone can help me.
I need to be able to serve banners in categories which are dependant on a session variable - and can't find a component which does that. So I'd like to extend the Joomla Banner component in order to select banners based on a session variable which contains the category path.
The correct session variable is being stored correctly.
In order to do this I added an option in the banners module .xml to allow for a session variable and the name of the session variable. This is being stored correctly in the module table within the params field along with the other module parameters.
Then I started on the
components > banners > com_banners > models > banners.php
by adding two lines of code in getListQuery where the SQL is assembled. They are:
$sess_vars = $this->getState('filter.sess_vars');
$sess_vars_name = $this->getState('filter.sess_vars_name');
But both variables contain nothing even though the ones the component already has can be retrieved fine. Without a doubt I need to change something somewhere else as well - but just can't figure out what to do.
Any help would be greatly appreciated.
The first thing to do is not hack the core files, hacking the core prevents you from using the built-in update feature to apply the regular bug fixes and security patches released by Joomla! (e.g. the recently released 2.5.9 version).
Rather make a copy of them and modify it so it's called something else like com_mybanners. Apart from the folder name and the entry point file (i.e. banners.php becomes mybanners.php) you will also want to update the components banners.xml to mybanners.php.(You will need to duplicate and modify both the front end /components/com_banners/ and /administrator/components/mybanners.php.)
Because of the way Banners work (i.e. banners are displayed in a module) you will also need to duplicate and modify /modules/mod_banners/,/modules/mod_banners/mod_banners.php and /modules/mod_banners/mod_banners.xml. Changing mod_banners to mod_mybanners in each location.
In Joomla! components the state is usually populated when JModel is instantiated, however, in this case the component is really about managing banners and recording clicks the display is handled by mod_banners. So, you will want to add some code to mod_mybanners.php to use the session variables you want to act on. Normally when a models state is queried you will collect the variables via JInput and add them to your object's state e.g.
protected function populateState()
{
$jApp = JFactory::getApplication('site');
// Load state from the request.
$pk = $jApp->input->get('id',0,'INT');
$this->setState('myItem.id', $pk);
$offset = $jApp->input->get('limitstart',0,'INT');
$this->setState('list.offset', $offset);
// Load the parameters.
$params = $app->getParams();
$this->setState('params', $params);
// Get the user permissions
$user = JFactory::getUser();
if ((!$user->authorise('core.edit.state', 'com_mycomponent')) && (!$user->authorise('core.edit', 'com_mycomponent')))
{
$this->setState('filter.published', 1);
$this->setState('filter.archived', 2);
}
}
The populateState() method is called when a state is read by the getState method.
This means you will have to change your copy of /components/com_banners/models/banner.php to capture your variables into the objects state similar to my example above.
From there it's all your own code.
You can find all of this information in the Developing a Model-View-Controller tutorial on the Joomla Doc's site
One of my jobs is to manage 58 sites for properties spread out across the country. They each have their own domain and are all housed in the same Dedicated Virtual Serve at Media Temple. The sites which are about 19 pages each use the exact same html/css/php code. The images are served to each site from a central repository living in different folders for each theme used.
What I want to do is to install one single installation of CI2 including the application folder because everything that is different between the sites is stored in the database. As long as I can give the controller a unique property number (which I would hope I could do when they access the index.php page in each domain), then all of my sites will work fine.
In all the answers I have read, the suggestion is to replicate the application folders and just reuse the core. What would work best for me is to also reuse the application folder. Then when I make a modification, it will cascade to all sites without me having to touch 58 pages.
Is this possible?
If all files are the same and the only thing changing between apps is the data from the database, then you can do this:
Point all domains to your docroot for the CI install
in your index.php, determine which db connection you need to use for the currently requested domain:
// index.php
$domain = $_SERVER['SERVER_NAME'];
switch ($domain)
{
case 'www.firstsite.com':
$this->load->database('firstsitedb');
break;
case 'www.secondsite.com':
$this->load->database('secondsitedb');
break;
default:
show_error('No Site Found');
break;
}
** OR **
If they each use the same database, and you need to be able to use a variable in your queries, then just set a constant based on the switch/case instead of loading a different database. Then you can use that constant throughout your application in your queries.
// index.php
$domain = $_SERVER['SERVER_NAME'];
$site_id = 0; // default
switch ($domain)
{
case 'www.firstsite.com':
$site_id = 1;
break;
case 'www.secondsite.com':
$site_id = 2;
break;
default:
show_error('No Site Found');
break;
}
define('SITE_ID', $site_id);
With Codeigniter 2.2, the index.php now allows the setting of a config array item (the feature is documented in that file). So it is possible to save the requested domain as a site variable in effect by doing this:
$assign_to_config['site_domain'] = empty($_SERVER['SERVER_NAME']) ? 'default.dev' : $_SERVER['SERVER_NAME'];
Later you could match this site_domain string against a database look-up to fetch the requisite content & theme views etc.