In a public function of my model I call
$user_type=$this->get_user_type();
In the same model I have
private function get_user_type()
{
$user_type='asd';
$asd_groups = (int)$config->get('asd_groups');
$ver_groups = (int)$config->get('ver_groups');
jimport( 'joomla.user.helper' );
$user_groups=JUserHelper::getUserGroups($user->id);
if(in_array($asd_groups,$user_groups)){
$user_type='asd';
}
if(in_array($ver_groups,$user_groups)){
$user_type='ver';
}
return $user_type;
}
The site give me a white page, if I comment the calling line "$this->get_user_type();" then it works...
I really don't understand what is wrong here.
There is not enough information or code here to help you… for example where is $config coming from and what is it? What version of Joomla is this on?
If $config is not defined as a global then that may be the source of the problem depending on your PHP setup.
Things you can do to help yourself find the problem, in Joomla's Global Configuration.
Set Error Messages to "Development" in Joomla (you are using a development site and not a live website right?)
Turn on Joomla's DEBUG mode
Then update your question with details of error messages, Joomla version and where this code is running (you say your model) and where $config is coming from.
Oh sure!
I have missed the two configuration variable when i moved the code from inside a function in a dedicated function.
I copied these two lines on the first row of the function and now it works!
$config = JComponentHelper::getParams(S_APP_NAME);
$user = JFactory::getUser ();
Related
Problem
When I try to add a block into my transactional email template in the following manner:
{{block type='core/template' area='frontend' template='invent/baskettimer/email_items.phtml' record=$record}}
I get the following error, and nothing is rendered.
CRIT (2): Not valid template file:frontend/base/default/template/invent/baskettimer/email_items.phtml
Troubleshooting
Normally this warning points to a typo which is breaking the inheritance but I have quadruple checked and this should work.
I then copied the file into the base and did a test, it rendered correctly.
Create a custom block and set the template, same error is displayed.
Theory
To me it seems template inheritance is broken / not implemented for emails, so it is always looking in base, I cannot put my templates there so I am not sure how to call them.
Possible workarounds
Render the block to html then send it to as a variable to render, problem with this is I am sending the emails from Model level and am having a hard time pre rendering the block, even with a helper.
Render the data using a method, don't really want to do this as it is message / against MVC.
Any help is much appreciated.
Bounty update
So I have traced down the problem, it is probably an easy solution now.
The problem is that I am calling it from a cronjob does not have the correct store view, it is fairly easy to replicate similar situation by using a shell script, then changing the _appCode to null.
<?php
require_once 'abstract.php';
class Mage_Shell_Shell extends Mage_Shell_Abstract
{
protected $_appCode = ''; // works - remove to not work
/**
* Run script
*
*/
public function run()
{
Mage::getModel('invent_baskettimer/email')->sendJob();
}
}
$shell = new Mage_Shell_Shell();
$shell->run();
So basically the question has become:
How do I call a block->toHtml() regardless of store view?
There is not way of setting a cronjob to be like that. Lucky magento lets you emulate your store views, see the following to emulate the default store.
public function cronjob()
{
$iDefaultStoreId = Mage::app()
->getWebsite()
->getDefaultGroup()
->getDefaultStoreId();
$appEmulation = Mage::getSingleton('core/app_emulation');
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($iDefaultStoreId);
.. do your stuff here ..
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
}
For more info see: http://inchoo.net/ecommerce/magento/emulate-store-in-magento/
I'm new one to opencart.is there any debug tools available for opencart ? .i don't know control flow of opencart execution.so i want to put break points,step into code,see variable values. please give any reference to that .thanks in advance.
I wrote a super simple little function for the loader class that I use 100 times a day. It really helps and you can call it from just about anywhere.
OPEN:
system/engine/loader.php
Right before the closing brace for the class add this method:
// adding testing method
public function test ($items, $quit = true) {
echo "<pre>";
print_r ($items);
echo "</pre>";
if ($quit):
exit;
endif;
}
Now anytime after the Controller is instantiated you can call:
$this->load->test($results);
OR:
$this->load->test($results, false);
if you're in a loop and don't want the script to exit.
Obviously substitute $results for whatever array or variable you want to test.
It's been a huge help to me.
You can of course add this via vqmod if you don't want to modify the core.
You are right. Opencart is very simple system.
In addition you can use xDebug - very useful tool.
Also, read system/logs/error.txt
error_reporting(E_ALL); // very helpful
die(print_r($_POST, true)); // print all POST data and break the code
you can use https://github.com/mithereal/opencart_inline_debuggers and just d($var); in the source where var is a varible or object
Hi i wanted to create a custom form to get input from the user, i can access the form from the url :
http://localhost/website/index.php/contest
but when i uploaded it to a server which has multiple website setup in the magento, i could not access the form like i used to on local server.
http://www.website.org/index.php/contest
i am stumped , i hit a wall i googled, i just don't know what to look for , any help will be greatly appreciated. Thanking anyone in advance
Magento routing is a sort of big topic to cover in a single Stack Overflow answer. You can read about the basics of setting up a controller here, and the probably in too much depth routing process here.
That said, here's some general debugging tips.
Can Magento see the module your controller is a part of? If not, you're probably missing your file in app/etc/modules. (look at the module list in `System -> Configuration -> Advanced -> Disable Module Output)
If your module is installed, Magento probably can't find your controller class. Eitehr because it's not there, of you have a case sensitivity issue. Add some temporary debugging code to the _validateControllerClassName function to determine why Magento can't find your controller.
You can find the _validateControllerClassName function here
#File: app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
protected function _validateControllerClassName($realModule, $controller)
{
$controllerFileName = $this->getControllerFileName($realModule, $controller);
if (!$this->validateControllerFileName($controllerFileName)) {
return false;
}
$controllerClassName = $this->getControllerClassName($realModule, $controller);
if (!$controllerClassName) {
return false;
}
// include controller file if needed
if (!$this->_includeControllerClass($controllerFileName, $controllerClassName)) {
return false;
}
return $controllerClassName;
}
Some var_dumps before the return false clauses should tell you why Magento can't find and/or include your controller class file.
I'm using this tutorial http://sumonbd.wordpress.com/2009/09/16/develop-multilingual-site-using-codeigniter-i18n-library/ for multilingual in codeigniter.
I've follow the instruction listed correctly. It does not gave me any error, but I couldn't say that it is working properly.
when I run through mysite.com/en/about and mysite.com/fr/about it always give me the default language which is english. I'm wondering if there is any configuration that I need to set to be able to work properly.
I'm thinking about this in config.php
$config['language']
and
this in autoload.php
$autoload['language']
Do I have to configure those? or any other configuration to work the multilingual properly.
After analyzing the code of CI and the codes in the blog I've come up to this solution.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class About extends CI_Controller {
function index()
{
// you might want to just autoload these two helpers
$this->load->helper('language');
$this->load->helper('url');
$this->getLang();
$this->load->view('about');
}
function getLang(){
$url = $_SERVER['REQUEST_URI'];
$lang = explode("/", $url);
if($lang[2] == 'en'){
// load language file
return $loadLang = $this->lang->load('english','english');
}
else if($lang[2] == 'fr'){
// load language file
return $loadLang = $this->lang->load('french','french');
}
else{
// load language file
return $loadLang = $this->lang->load('english','english');
}
return false;
}
}
I've created the function getLang() in which I load the language file.
$this->lang->load('language_file','language_folder');
Sorry, you don't provide enough information about what you have done. But I'll try to answer.
I've try the updated tutorial, and it's works like a charm.
First, you point to an out to date tutorial. This is the source of your link with an update: source
Second, a file prefixed with MY_ (default configuration) is a core classes ( see Core Classes ) not a library and should be placed on application/core directory.
Third, in your view file, try to avoid using php short tag (<?=$variabel;?>) because not all server configuration enable php short tag. Use normal echo tag instead <?php echo $var; ?>. Longer, but worth it as you write the standard pattern.
As I said before, if you follow the updated tutorial your script should work as mine. I hope this help. Sorry for my English, correct me if I'm wrong.
i think you should have a look at URI-Language-Identifier i use it for my multilingual projects, and its working as it should.
I'm using CodeIgniter 2 and have installed Ion Auth and also the News tutorial that comes with CodeIgniter.
In the News Controller, the element for the page title is written like this...
$data['title'] = 'Page Title';
However, in the Ion Auth Controller, the element for the page title is written like this...
$this->data['title'] = 'Page Title';
They both seem to work equally well, so can anyone explain the difference(s)? Maybe Ion Auth was written for an older version of CodeIgniter? Is there any practical reason why I'd want to use one over the other? Please link to sources as needed.
I guess it's the author's preference. He likes to use a class property to store the view's data. It allows him to share it across methods. If you look at the author's other projects (Source 1, 2, 3), you can see two examples (source 1 & 2 goes together).
On a side note, for your project, this could allow you to extend the Auth controller with more view data.
class MY_Auth extends Auth {
function __construct()
{
parent::__construct();
}
function index()
{
$this->data['foo'] = 'bar';
parent::index();
}
}
That would allow you to use the $foo variable to your authentication view. (/auth/index in this case.)
In my own projects, I like to use a protected property for my view's data. It does give you much more freedom than a local variable. You don't need to pass the view's data as an argument all the time and you can easily extend your controllers afterward.
Hope this helps!
if you are going to use this $this->data it means you can access $this->data through out the class methods. On the other hand if you are using $data it is only available for the current scope or method and if you need data some where else then you will have to pass it as parameters to the other methods.
Adding $this on the data variable, makes it to be accessible through the class.
I believe the $data or $this->data is only used for "View". It will be passed from the "Controller" to the "View", so we can access that variable through the "View".
So, there will be no differences on the "View" side.