Monday, September 26, 2016
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
I am trying to use this filter in my HTML as
But this didn't worked out so I had to use filter in my controller.Here is how I did the same
And then I used this in my Html as follows
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>
Labels:
addition,
Angular,
angularjs,
controller,
custom,
expression,
filter,
Javascript,
js,
operator
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
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
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
See the line in Bold this must be done to get errors set
In the view
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.
You need to place your favicon.ico file in/webroot/img directory
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
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
After that my Install went smooth.
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
After that my Install went smooth.
Apache2-Forbidden You don't have permission to access /dir/ on this server
Recently on restarting my Apache Server on Ubuntu I came across following error
Forbidden You don't have permission to access /dir/ on this server
After a bit of google I solved this by granting permissions to my server directory and resetting my httpd.conf directory access levels as follows
Since I am working on Ubuntu I will be using Ubuntu locations your locations can very depending upon your linux distribution
In Ubuntu httpd.conf file is place under
/etc/apache2/sites-available directory
if you list directory contents you will find files like
000-default.conf 000-default.old example.com~
000-default.conf~ default-ssl.conf
Out of these first one is the httpd.conf file in concern(this is how Ubuntu stores it)
First make a copy of the same as you can see I have made a copy of the same 000-default.old using following command
sudo cp 000-default.conf 000-default.old
Now Alter the 000-default.conf as follows
Next grant permissions to your directory as
Forbidden You don't have permission to access /dir/ on this server
After a bit of google I solved this by granting permissions to my server directory and resetting my httpd.conf directory access levels as follows
Since I am working on Ubuntu I will be using Ubuntu locations your locations can very depending upon your linux distribution
In Ubuntu httpd.conf file is place under
/etc/apache2/sites-available directory
if you list directory contents you will find files like
000-default.conf 000-default.old example.com~
000-default.conf~ default-ssl.conf
Out of these first one is the httpd.conf file in concern(this is how Ubuntu stores it)
First make a copy of the same as you can see I have made a copy of the same 000-default.old using following command
sudo cp 000-default.conf 000-default.old
Now Alter the 000-default.conf as follows
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Next grant permissions to your directory as
sudo chown -R $USER:$USER /var/www
sudo chmod -R g+rw /var/www
You will now be able to access your localhost directory
Subscribe to:
Posts (Atom)