Magento $this->__('Create an Account') - magento

In Magento $this->__('Create an Account') How this echo Create an Account?
abstract class Mage_Core_Helper_Abstract{ public function __()
{
$args = func_get_args();
$expr = new Mage_Core_Model_Translate_Expr(array_shift($args), $this->_getModuleName());
array_unshift($args, $expr);
return Mage::app()->getTranslator()->translate($args);
}
I saw that __ function in Mage_Core_Helper_Abstract Class.but i cant understand Mage::app()->getTranslator()->translate($args) what's happending in that getTranslator function.
public function getTranslator()
{
if (!$this->_translator) {
$this->_translator = Mage::getSingleton('core/translate');
}
return $this->_translator;
}
Mage::getSingleton('core/translate') what's happening there ? and why in this function call like core/translate which file its denote and how it Create an Account text?

You might search how the magento translator works
What ever text is written in $this->_('') will dynamically translated to the current locale which is loaded in your current store(That text must be specified in magento-root/app/locale//.csv)
I think the below answer might be helpfull
How does Magento translate works?

Related

Get shipping address county in Magento 2 observer

Hi I have a custom module . I want to get shipping country inside
public function execute(\Magento\Framework\Event\Observer $observer)
{
Please let me know how can i get this this ?
I have seen this code for postcode , but i am not sure his is working or not
$postCode = $this->_checkoutSession->getQuote()-getShippingAddress()->getPostcode();
I need shipping address country name in public function execute. Please help .
declare a public variable and intialize the variable like below ,then you will be able to use it in your execute method
class Example {
public $_checkOutSession;
public function __construct(\Magento\Customer\Model\Session $checkOUtSession)
{
$this->_checkOutSession = $checkOutSession;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$postCode = $this->_checkoutSession->getQuote()->getShippingAddress()->getPostcode();
}
}
It depends on which observer do you want to get it. Can you provide a more specific scenario?
In which checkout session currently has a quote. You can use the above solution from Reggie.
Or else you need to initialize quote/order to get it.

How to stop slug generation in OctoberCMS

When I write non-unicode letters in OctoberCMS Rainlab blog title, it's converted to English letters such as this:
موضوع جديد
is converted to: modoaa-gdyd
I don't want this, I want only to replace spaces with hyphen to be for example:
موضوع-جديد
How can I do that?
Hmm for now it seems we are not able to extend js plugin for give purpose
but we can extend plugin to not use slug type
you can add this code to any of your plugin's boot method
boot method is imp
<?php namespace HardikSatasiya\DemoTest;
use System\Classes\PluginBase;
class Plugin extends PluginBase
{
public function registerComponents()
{
}
public function registerSettings()
{
}
public function boot() {
\Event::listen('backend.form.extendFieldsBefore', function($widget) {
// You should always check to see if you're extending correct model
if(!$widget->model instanceof \RainLab\Blog\Models\Post) {
return;
}
// now we remove type = slug , and use exact
// as type = slug will convert chars ARABIC_MAP to english so
$widget->fields['slug']['preset']['type'] = 'exact';
});
}
}
It will not solve your complete problem but it can simply copy your blog-title exactly in to slug, in slug text-box then you need to add / at the beginning and then you also need to place ' ' => '-' (dash at spaces) manually.
sorry this will not solve your whole issue, but just saves you from copying title to slug again and again.
Add this function as a helper in your app and reuse it
public static function generateSlug($title)
{
$title = strtolower($title);
$title = preg_replace("/[\s-]+/", ' ', $title);
$title = preg_replace("/[\s_]/", '-', $title);
return $title;
}
$slug = Helpers::generateSlug('موضوع جدید', '-');
//will produce "موضوع-جدید"
Or use this package
Sluggable Persian
I solved this problem by editing the following file:
modules\system\assets\ui\storm-min.js
I emptied the following variables:
ARABIC_MAP={},PERSIAN_MAP={}
and edited the slugify function by replacing this line:
slug=slug.replace(/[^-\w\s]/g,'')
with this:
slug=slug.replace(/[^-\w\sء-ي]/g,'')
so, now the slug accepts Arabic characters normally

CodeIgniter URI Routing: remove method name index from URL

I am working with CodeIgniter (V:2.2.6) and I have a simple class User with some basic methods like create, update, edit, delete and index. For the index function, I am using an argument $user (which is the second URI segment) in order to display some information regarding that user. So the default URL looks like:
/user/index/john
to display some information about the user 'john'.
Now, I want to remove the term 'index' from the URL, so that it looks like:
/user/john
For that purpose I have added the following rule in routes.php.
$route['user/(:any)'] = "user/index/$1";
It serves the purpose, but it prevents accessing other functions like /user/create and goes inside /user/index automatically. To solve this problem, I can not see any other way except manually adding routing rules like
$route['user/create'] = "user/create";
for each method of the User class, which is not cool at all. So, please can anyone suggest me a better way of routing under the current circumstances?
Here are my codes:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller {
public function index($user = '') {
echo "index!";
}
public function create() {
echo 'create!';
}
}
Note: I have gone through the CodeIgniter documentation for URI Routing and another similar question here, but could not figure out a promising solution. And please don't suggest for CodeIgniter version update.
I'm not sure, if this is the answer you like, but i think it should work.
Just put this function in your user controller.
public function _remap($method)
{
if (method_exists($this, $method))
{
$this->$method();
}
else
{
$this->index($method);
}
}

ajax bugs in codeigniter

i have a controller having following script
class get extends CI_Controller
{
function get_password()
{
$this->load->model('fetch_model');
$user_pass=$this->fetch_model->get_password();
$data['user_pass'] = json_encode($user_pass);
echo $data['user_pass'];
}
}
and a script on view page as this
function get_password(){
$.post("<?php echo base_url();?>admin.php/get/get_password",function(data)
{
for(i=0;i<data.length;i++)
{
$('#password').val(data[i].password);
$('#username').val(data[i].username);
}
},"json");
}
now if i use the following script in model then the ajax post is working perfectly..
class fetch_model extends CI_Model
{
function get_password()
{
return $this->db->query("SELECT * FROM td_admin_user")->result_array();
}
}
but when i change the model script into this, then the ajax script isnt working
class fetch_model extends CI_Model
{
function get_password()
{
foreach($this->db->query("SELECT * FROM td_admin_user")->result() as $r_pass)
{
$pass=$r_pass->password;
$user=$r_pass->username;
}
$user_pass=array('username'=>$user,
'password'=>$pass);
return $user_pass;
}
}
but to be very frankly, i need to send data in the following way
$user_pass = array('username'=>$user, 'password'=>$pass);
and not as result_array()
so please help me in this context, thanks in advance
This is not a bug! Did you even look at what type of data is returned in each call?
In your JS, you are using:
$('#password').val(data[i].password);
Where data is an indexed array - exactly what is returned by ->result_array()
But you want it to be a key based array:
$user_pass=array('username'=>$user, 'password'=>$pass);
If that's the case, you should forget using the for loop on JS (specially if your query only results in one row) and use
$('#password').val(data.password);
Instead.
Also look at console.log (if you are using firebug/developer tools) and try print_r or var_dump on the PHP side to understand the data formats you are returning.

How To Start Using Kostache?

I just asked a question ( Templates In Kohana 3.1 ) about templates and now I know that I should use Kostache. It's a module for the Mustache template language.
Anyway, I just enabled Kostache module for my Kohana 3.1 and all works. It's installed correctly! What to do next? How to use it?
Where should I put my views now?
What my controller should extend?
How to assign variable?
How to make header, footer etc. for views?
Maybe there are step to step guide for it? This and this won't help me a lot...
Where should I put my views now?
View classes contain logic for your templates and by convention should be stored in classes/view/{template name}.php
Templates contain your HTML and should be stored in the templates directory in the root of your module, e.g. templates/login.mustache
By default kostache will try and work out the location of the template based on your view class' name.
If your view class is called View_Admin_Login then kostache will look for templates/admin/login.mustache
What my controller should extend?
You do not need to extend any special controllers, the normal Controller will work fine as a base.
How to assign variable
Controller:
$view = new View_Admin_Login;
$view->message = 'Hello';
$this->response->body($view->render());
Template:
{{message}}
Of course, any methods or variables you declare in your view class will also be available in
the template. If there is a class variable and method with the same name then the method will always take precedence over the variable.
How to make header, footer etc. for views
It will help if you read the kostache guide. The idea is that your views extend Kostache_Layout, see also the layout template
There's lots of demos and examples in both of the repositories that you said won't help you.
Try this...
//application/classes/controller:
class Controller_Test extends Controller {
public function action_index()
{
$view = new View_Home;
$this->response->body($view->render());
}
}
//application/classes/view/Home.php:
class View_Home {
public $name = "Chris";
public $value = 10000;
public function taxed_value() {
return $this->value - ($this->value * 0.4);
}
public $in_ca = true;
protected $_layout = 'home';
}
//application/templates/home.mustache:
Hello {{name}}
You have just won ${{value}}!
{{#in_ca}}
Well, ${{ taxed_value }}, after taxes.
{{/in_ca}}
In your APPPATH/classes/controller/Test.php:
class Controller_Test extends Controller{
public function action_index()
{
$renderer = Kostache::factory();
$this->response->body($renderer->render(new View_Test));
}
}
In your MODPATH/KOstache/classes/view/Test.php:
class View_Test
{
public $name = "Chris";
public $value = 10000;
public function taxed_value() {
return $this->value - ($this->value * 0.4);
}
public $in_ca = true;
}
In your MODPATH/KOstache/classes/templates/test.mustache:
Hello {{name}}
You have just won ${{value}}!
{{#in_ca}}
Well, ${{ taxed_value }}, after taxes.
{{/in_ca}}
In the following example, do not pay attention to naming classes and inheritance:
More examples on GitHub

Resources