Это моя первая попытка написать свою копмоненту под Joomla.
На локальном сервере все работает хорошо, с хостингом возникают проблемы.
http://walletit.cqhost.net/index.php?option=com_accountman&view=account&Itemid=53При нажатии на кнопку, вываливается пустая страничка:(
Права на доступ к файлам и папкам проверял.
Код темплейта с которого идет переход:
<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<h1>Your Credit Score now <?php echo $this->greeting; ?> $</h1>
<form action="index.php" method="post" name="buyForm" id="buyForm">
<table>
<tr>
<td>
<h2>Enter ammount of credits you want to buy</h>
</td>
<td align="center">
<input name="ammount" value="" />
</td>
<td align="center" >
<input type="submit" name="buy_but" value="Buy" />
<!--<input type="submit" name="buy_but" value="Buy" onclick='index.php?option=com_accountman>controller=account>task=buy' /> -->
</td>
</tr>
</table>
<form>
<input type="hidden" name="option" value="com_accountman" />
<input type="hidden" name="task" value="buy" />
<input type="hidden" name="controller" value="Buy" />
</form>
Код контроллера:
<?php
/**
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.application.component.controller');
require_once( JPATH_COMPONENT.DS.'views\\vbuy\\view.html.php' );
/**
* Hello World Component Controller
*
* @package Joomla.Tutorials
* @subpackage Components
*/
class AccountControllerBuy extends JController
{
/**
* Method to display the view
*
* @access public
*/
function display()
{
parent::display();
}
function __construct()
{
parent::__construct();
$this->registerTask( 'buy' , 'buy' );
}
function buy()
{
JRequest::setVar( 'view', 'Vbuy' );
$view = JRequest::getVar('view', 'Vbuy');
$inp = JRequest::getInt('ammount');
if ($inp >0){
$vn = 'AccountView'.$view ;
$model = &$this->getModel( $view ) ;
if (!JError::isError( $model )) {
$v = new $vn( $inp) ;
$v->setModel( $model, true );
$v->display();
}
}
}
}
?>
Код модели:
<?php
// Check to ensure this file is included in Joomla!
defined
('_JEXEC')
or
die();
jimport( 'joomla.application.component.model' );
/**
* Hello Model
*
* @package Автор
* @subpackage Components
*/
class AccountModelVbuy extends JModel
{
/**
* Gets the greeting
* @return string The greeting to be displayed to the user
*/
// public $user ;
/* function getUser(){
return $this->user;
}
*/
function getScore()
{
$db = JFactory::getDBO();
$query = 'SELECT summ FROM account';
$db->setQuery( $query );
$greeting = $db->loadResult();
return $greeting;
}
function setScore($sco)
{
$db = JFactory::getDBO();
$sum = AccountModelVbuy::getScore();
if ($sum < $sco){
$query = 'UPDATE account SET summ = 10000';
$db->setQuery( $query );
$res = $db->query();
} else {
$sum -=$sco;
$query = 'UPDATE account SET summ ='.$sum ;
$db->setQuery( $query );
$res = $db->query();
}
return $res;
}
function buy($cred)
{
$score = AccountModelVbuy::setScore($cred);
$db = JFactory::getDBO();
$date = date("j.F.Y.") ;
$time = date("h:i:s") ;
$pass = mt_rand(1,100000);
$user = array ("id" => 0, "time" => $time, "date" => $date, "pass" => $pass, "cred" => $cred);
//$this->user = $user;
$query = 'INSERT INTO user_c (time, pass, cred) VALUES(CURDATE(),'.$pass.','.$cred.')';
$db->setQuery( $query );
if (!$db->query()) {
echo $db->stderr();
} else {
$id = $db->insertid();
$sc = AccountModelVbuy::getScore();
$user = array ("id" => $id, "time" => $time, "date" => $date, "pass" => $pass, "cred" => $cred, "score" => $sc);
// $this->user = $user;
}
return $user;
}
}
?>
Код вьюхи:
<?php
/**
* @package Joomla.Tutorials
* @subpackage Components
* @link http://dev.joomla.org/component/option,com_jd-wiki/Itemid,31/id,tutorials:modules/
* @license GNU/GPL
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.view');
/**
* HTML View class for the HelloWorld Component
*
* @package HelloWorld
*/
class AccountViewVbuy extends JView
{
var $score;
public $user = array();
function AccountViewVbuy($in) {
parent::__construct();
$this->score = $in ;
}
public function getScore(){
return $this->score;
}
function display($tpl = null)
{
$model = $this->getModel('vbuy');
$user = $model->buy($this->score) ;
$sc = $model->getScore();
$this->assignRef( 'user', $user['id']);
$this->assignRef( 'time', $user['time']);
$this->assignRef( 'pass', $user['pass']);
$this->assignRef( 'cred', $user['cred']);
$this->assignRef( 'date', $user['date']);
$this->assignRef( 'score', $sc);
parent::display($tpl);
}
}
?>