I created component for joomla according to mvc structure .I have some variable in my view and want to save that variable into database by model.My file structure:
-models
--contact.php
-views
--contact
---tmpl
----default.php
----default_comajax.php
---view.ajax.php
---view.html.php
My variable is in view.ajax.php and I want to save this variable within contact.php. My view.ajax.php
<?php
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.view');
class contactfViewcontactf extends JViewLegacy
{
function display($tpl = null)
{
$name = "test";
$this->get('Msg');
parent::display(comajax);
}
}
and my contact.php is
<?php
defined('_JEXEC') or die('Restricted access');
jimport('joomla.application.component.modelitem');
class contactfModelcontactf extends JModelItem
{
public function getMsg()
{
$db =& JFactory::getDBO();
$query = "INSERT INTO #__rtuyds (email) VALUES ('$name')";
$db->setQuery($query);
$db->query();
}
}
How can I get access $name in contact.php? the DB query executes and insert a new row in table but new row is empty and $name is not saved.