Hello, everything works fine in my application but I just discovered something strange
whenever I hit: '{sitename}/tags/store' in the browser, the 'lastHitPostFk' at tagFk(4) is incrememted by 2 instead of 1 (this increments by one in my old no-module application) below is the files seperated by /////////////////////
THE VERY CONTROLLER//////////////////////////////
<?php
namespace Frontend\Controller;
class TagsController extends AaController
{
public function initialize()
{
}
public function indexAction()
{
}
public function storeAction()
{
$selectedHitCount = \Model\UserTags::findFirst(
"tagFk = 4"
);
$selectedHitCount->hitsCount++; //<<<POINT OF PROBLEM: THIS INCREMENTS BY 2
$selectedHitCount->lastHitPostFk = 3;
$selectedHitCount->update();
//$this->view->disable(); //<<<WHENEVER I UNCOMMENT THIS IT INCREMENTS BY ONE AS EXPECTED
}
public function topicsearchAction()
{
}
}
CONTROLLER ENDS//////////////////////////////////////////////////////////
THE MODEL /////////////////////////////////////////////
<?php
namespace Model;
class UserTags extends AaModel
{
public $userTagsAi;
public $userFk;
public $tagFk;
public $hitsCount;
public $lastHitPostFk;
public $lastHitTime;
public $activeKey;
public $disabledKey;
public function initialize()
{
}
}
MODEL ENDS//////////////////////////////////////////////////////////////////////////////////
THE MUDULE FILE////////////////////////////////////////////////////////////////////////////////
<?php
namespace Frontend;
use Phalcon\Loader;
use Phalcon\DiInterface;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\ModuleDefinitionInterface;
class Module implements ModuleDefinitionInterface
{
public function registerAutoloaders(DiInterface $di = null)
{
$loader = new Loader();
$loader->registerNamespaces(array(
'Frontend\Controller' => APP_PATH . 'app/modulefrontend/controllers/',
'Model' => APP_PATH . 'app/models/',
'Library' => APP_PATH . 'app/library/',
'Traitfunction\db' => APP_PATH . 'app/traits/db/',
'Traitfunction\user' => APP_PATH . 'app/traits/user/'
));
$loader->register();
}
public function registerServices(DiInterface $di = null)
{
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('Frontend\Controller');
return $dispatcher;
});
$view = $di->get('view');
$view->setViewsDir(APP_PATH . 'app/modulefrontend/views/');
$di->set('view', $view);
}
}
MODULE ENDS////////////////////////////////////////////////////////////////////////////////
THE BOOTSTRAP FILE (index)/////////////////////////////////////////////////////////
<?php
error_reporting(E_ALL);
use Phalcon\Di\FactoryDefault;
use Phalcon\Mvc\Application;
use Phalcon\Config\Adapter\Php as ConfigPhp;
define('APP_PATH', realpath('..') . '/');
try {
$requestPart = explode('/', htmlspecialchars($_SERVER['REQUEST_URI'])); //*/*partitioning the request for individual array use and testing*/
/**
* Injecting all functions needed by the application from a file that also requires a list of all of them
*/
require_once APP_PATH . 'app/globalconfig/includes/aafuncs.php';
$di = new FactoryDefault();
/**
* Load Base Routes
*/
require_once APP_PATH . 'app/globalconfig/routes/baseroutes.php';
/**
* Load Global Services
*/
require_once APP_PATH . 'app/globalconfig/globalservices/basicservices.php';
/**
* Create an Application
*/
$application = new Application($di);
$application->setDefaultModule('modulefrontend');
/**
* Register the installed modules
*/
$application->registerModules(
array(
'modulefrontend' => array(
'className' => 'Frontend\Module',
'path' => '../app/modulefrontend/Module.php',
),
'moduleadmin' => array(
'className' => 'Admin\Module',
'path' => '../app/moduleadmin/Module.php',
)
)
);
if ($requestPart[2] == 'a') { /*bootstrap codes that is needed by the ajax request and not the view(ed) request*/
$application->useImplicitView(false);
};
/**
* Finally, handle the request!
*/
echo $application->handle()->getContent();
/**
* If e wan fall hand
*/
} catch (Exception $e) {
echo $e->getMessage() . '<br>';
echo '<pre>' . $e->getTraceAsString() . '</pre>';
}
bootstap ends/////////////////////////////////////
THE (basic)SERVICE FILE/////////////////////////////////////////////////////////
<?php
use Phalcon\Mvc\View;
use Phalcon\Crypt;
use Phalcon\Security;
use Phalcon\Escaper;
//use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\Url as UrlResolver;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
//use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
use Phalcon\Mvc\Model\Metadata\Files as MetaDataAdapter;
use Phalcon\Session\Adapter\Files as SessionAdapter;
//use Phalcon\Flash\Direct as Flash;
//use Phalcon\Di;
//use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Manager as ModelsManager;
//use Phalcon\Db\Adapter\Pdo\Sqlite as Connection;
use Phalcon\Mvc\Model\Metadata\Memory as MetaData;
use Phalcon\Flash\Direct as FlashDirect;
use Phalcon\Http\Response\Cookies;
$di->setShared('db', function() {
return new DbAdapter(array(
"host" => "localhost",
"username" => "root",
"password" => "",
"dbname" => "mydatabase"
));
});
$di->setShared('url', function () {
$url = new UrlResolver();
$url->setBaseUri('/mysite/');
return $url;
});
$di->set('registry', function() {
$registry = new \Phalcon\Registry();
return $registry;
});
$di->set('flash', function () {
$flash = new FlashDirect(
array(
'error' => 'alert alert-danger',
'success' => 'alert alert-success',
'notice' => 'alert alert-info',
'warning' => 'alert alert-warning'
)
);
return $flash;
});
$di->set('cookies', function () {
$cookies = new Cookies();
$cookies->useEncryption(false);
return $cookies;
});
$di->set('modelsManager', new ModelsManager());
$di->set('modelsManager', function () {
$manager = new ModelsManager();
return $manager;
});
// Use the memory meta-data adapter or other
$di->set('modelsMetadata', new MetaData());
$di->set('view', function () {
$view = new View();
return $view;
});
$di->setShared('sessionj', function () {
$session = new Phalcon\Session\Adapter\Files();
$session->start();
return $session;
});
$di->set('session', function () {
$session = new SessionAdapter();
$session->start();
return $session;
});
$di->set('assets', function () {
$assets = new Phalcon\Assets\Manager();
return $assets;
});
$di->set('escaper', function () {
$escape = new \Phalcon\Escaper();
$escape->setHtmlQuoteType('ENT_HTML');
return $escape;
});
SERVICE FILE ENDS //////////////////////////////////
Please help look at the entire code gainst PHP/PHALCON principle misconception, I tend to code through trial and error and with source code rather than documentation...also check my view, dispatcher, namespacing, loading, modul(ing) implementations