Pages

Friday, September 30, 2016

Angular Js- Using minified version of Controller,filter js files

Using minifed version of controller JS Files

Here we will use a controller as an example same can be used for Filters

One important thing to note when we isolate controller from our HTML file is during its minification.
The minification also minifies variable in controller and $scope,$http,$filter may become variables a,b,c which are not recognized by angular see the minified version of above controller.js is as follows

controller.js

 angular.module('myApp',[]).controller('myCtrl',function($scope){  
 $scope.names=[  
 {name:'Gaurav',country:'India'},  
 {name:'Mike',country:'USA'},  
 {name:'Steve',country:'Denmark'}  
 ];  
 });  

controller.min.js

 angular.module("myApp",[]).controller("myCtrl",function(n){n.names=[{name:"Gaurav",country:"India"},{name:"Mike",country:"USA"},{name:"Steve",country:"Denmark"}]});  

Here $scope becomes n and this will not be recognized by angular js.To over come this problem use code controller code in controller.js as

controller.js

 angular.module('myApp',[]).controller('myCtrl',["$scope",myCtrl]);  
 function myCtrl($scope){  
 $scope.names=[  
 {name:'Gaurav',country:'India'},  
 {name:'Mike',country:'USA'},  
 {name:'Steve',country:'Denmark'}  
 ];  
 };  

In this we isolate the Controller function but we also tell the module that the first parameter of this function will be "$scope"

The Minified version of this file is

controller.min.js

 function myCtrl(n){n.names=[{name:"Gaurav",country:"India"},{name:"Mike",country:"USA"},{name:"Steve",country:"Denmark"}]}angular.module("myApp",[]).controller("myCtrl",["$scope",myCtrl]);  

Above file also changes the parameter $scope of the function to "n" but when final call is made to function the first parameter is sent as $scope

Monday, September 26, 2016

open cart 2.3 change Theme

To change in open cart 2.3

1. Go to Admin=>Extensions(main menu)=>Extensions(sub menu)




2. Select Themes as Extension Type

3. Click on Edit Action in Your store(blue button in above image) and select your theme directory


That's it

Saturday, September 24, 2016

Angular Js- Use a filter in expression with javascript addition operator

Recently in one of my Projects I was stuck up in an issue regarding filters

Here is My Custom Filter

       app.filter('alterCap',function()   
       {  
         return function(x)   
         {  
           var i, c, txt = "";  
           for (i = 0; i < x.length; i++) {  
             c = x[i];  
             if (i % 2 == 0) {  
               c = c.toUpperCase();  
             }  
             txt += c;  
           }  
           return txt;  
         };  
       });  

I am trying to use this filter in my HTML as

 {{ x.country|alterCap + ":" + x.capital|alterCap }}  

But this didn't worked out so I had to use filter in my controller.Here is how I did the same

 app.controller("myCtrl",function($scope,$filter){  
         $scope.capitals = [  
         {country:'India',capital:'Delhi'},  
         {country:'Sri Lanka',capital:'Colombo'},  
         {country:'Afganistan',capital:'Kabul'},  
         {country:'Bhutan',capital:'Norway'},  
         {country:'Nepal',capital:'Thimphu'},  
         {country:'Japan',capital:'Tokyo'},  
         {country:'China',capital:'Beijing'},  
         {country:'Russia',capital:'Moscow'},  
         {country:'USA',capital:'Washington, D.C.'}  
         ];  
         $scope.applyAlterCap = function(movie){  
           return $filter('alterCap')(movie);  
         };  
       });  

And then I used this in my Html as follows

 <p>Using Custom Filter with addition operator inside expression</p>  
     <ul>  
       <li ng-repeat="x in capitals | orderBy:'capital'">  
         {{ applyAlterCap(x.country) + ":" + x.capital }}  
       </li>  
     </ul>  

Tuesday, September 20, 2016

Ubuntu boots into command line after update

I recently faced this issue after updating to Ubuntu 15.10 and was looking for solutions until this one worked for me

Enter into recovery mode from grub and run the following  command

sudo dpkg --configure -a

Monday, January 4, 2016

Symfony-Error-Annotation not Imported

[Semantical Error] The annotation "@Template" in method AppBundle\Controller\DefaultController::indexAction() was never imported. Did you maybe forget to add a "use" statement for this annotation? in /var/www/symfony_learn_2_6/src/AppBundle/Controller/ (which is being imported from "/var/www/symfony_learn_2_6/app/config/routing.yml"). 

Recently while working on symfony I encountered above error.The resolution is simple we just need to add Sensio annotation handler for the above annotation.So in this case since annotation handler for template is missing we need to add 

Sensio\Bundle\FrameworkExtraBundle\Configuration\Template

above the controller.Similerly if annotation handler for route is missing then we can add 

Sensio\Bundle\FrameworkExtraBundle\Configuration\Route

Sunday, December 27, 2015

Symfony-Generate Bundle Option not working in app/console

Recently in One of the symfony dumps I gathered from my IT team had an issue due to some reason "Generate Bundle" option was not working from app/console list -- raw

Solution :

Add following lines in File composer.json

"required-dev":{
"sensio/generator-bundle": "~2.3"
}

File AppKernal.php should have

new Sensio\Bundle\GeneratorBundle\SensioGenerator();

That's it

Thursday, July 30, 2015

Cakephp 2.0-Validations not working

Many a times Our custom Validations do not work in cakephp due to very tiny small errors.Here is a piece of my research and development which might help you
 In the controller
       if (!empty($this->data))   
       {  
         $this->User->set($this->data);  
         if ($this->User->validates())   
         {  
           // it validated logic  
           echo "Yes we can proceed";  
         }   
         else   
         {  
           // didn't validate logic  
           $errors = $this->User->validationErrors;  
           pr($errors);  
         }  
       }  

See the line in Bold this must be done to get errors set

In the view
   <?php   
       if($this->Form->isFieldError('User.username'))  
       {  
         echo $this->Form->error('User.username', null, array('class' => 'message'));   
       }  
       ?>  
Now set the class to taste and you will get error message in view in desired color.

Thursday, July 9, 2015

Cakephp 2.0-Adding favicon to your website

I was able to add a favicon to my website using code mentioned.This one is trusted and working.

 echo $this->Html->meta('favicon.ico','img/favicon.ico',array('type' => 'icon'));  

You need to place your favicon.ico file in/webroot/img directory

Sunday, April 5, 2015

Cakephp 3.0-Where IN Condition with list

So here comes Cakephp 3.0 with all new syntax new ORM and many other changes.I find myself struggling with Cakephp this hard since I used cakephp 1.3 for the first time.

But here is My first struggle to help you with

  return $this->find('list',['keyField' => 'id', 'valueField' => 'name'])->where([  
          'id IN'=>$nearCitys  
       ])->toArray();  

Saturday, April 4, 2015

Cakephp 3.0-Installing from Composer

Recently I was trying to install cakephp 3.0 from composer which was throwing some cache errors as such my install was unsuccessfull

Here is what I did to correct the same

When you run composer to install something let us suppose cakephp 3.0 it creates a cache in your home directory.In my case location was

/home/gaurav/.composer

 This location has a cache folder which works for composer installation.This is not writable by default so this should b provided write permissions also Cakephp 3.0 requires
  • mbstring extension
  • intl extension
which must be installed in advanced(google it to get concerned installation repository for your distribution)

After that my Install went smooth.